Home | History | Annotate | Download | only in os
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.example.android.apis.os;
     18 
     19 import junit.framework.TestCase;
     20 import android.test.suitebuilder.annotation.SmallTest;
     21 
     22 /**
     23  * An example of a true unit test that tests the utility class {@link MorseCodeConverter}.
     24  * Since this test doesn't need a {@link android.content.Context}, or any other
     25  * dependencies injected, it simply extends the standard {@link TestCase}.
     26  *
     27  * See {@link com.example.android.apis.AllTests} for documentation on running
     28  * all tests and individual tests in this application.
     29  */
     30 public class MorseCodeConverterTest extends TestCase {
     31 
     32     @SmallTest
     33     public void testCharacterS() throws Exception {
     34 
     35         long[] expectedBeeps = {
     36                 MorseCodeConverter.DOT,
     37                 MorseCodeConverter.DOT,
     38                 MorseCodeConverter.DOT,
     39                 MorseCodeConverter.DOT,
     40                 MorseCodeConverter.DOT};
     41         long[] beeps = MorseCodeConverter.pattern('s');
     42 
     43         assertArraysEqual(expectedBeeps, beeps);
     44     }
     45 
     46     private void assertArraysEqual(long[] expected, long[] actual) {
     47         assertEquals("Unexpected array length.", expected.length, actual.length);
     48         for (int i = 0; i < expected.length; i++) {
     49             long expectedLong = expected[i];
     50             long actualLong = actual[i];
     51             assertEquals("Unexpected long at index: " + i, expectedLong, actualLong);
     52         }
     53     }
     54 }
     55