exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

test_hamming.c (2211B)


      1 #include "vendor/unity.h"
      2 #include "../src/hamming.h"
      3 
      4 void setUp(void)
      5 {
      6 }
      7 
      8 void tearDown(void)
      9 {
     10 }
     11 
     12 void test_empty_strands(void)
     13 {
     14    TEST_ASSERT_EQUAL(0, compute("", ""));
     15 }
     16 
     17 void test_rejects_null_strand(void)
     18 {
     19    TEST_ASSERT_EQUAL(-1, compute(NULL, "A"));
     20 }
     21 
     22 void test_rejects_other_null_strand(void)
     23 {
     24    TEST_ASSERT_EQUAL(-1, compute("A", NULL));
     25 }
     26 
     27 void test_no_difference_between_identical_strands(void)
     28 {
     29    TEST_ASSERT_EQUAL(0, compute("A", "A"));
     30 }
     31 
     32 void test_identical_long_strands(void)
     33 {
     34    TEST_ASSERT_EQUAL(0, compute("GGACTGA", "GGACTGA"));
     35 }
     36 
     37 void test_hamming_distance_for_single_nucleotide_strand(void)
     38 {
     39    TEST_ASSERT_EQUAL(1, compute("A", "G"));
     40 }
     41 
     42 void test_complete_hamming_distance_for_small_strand(void)
     43 {
     44    TEST_ASSERT_EQUAL(2, compute("AG", "CT"));
     45 }
     46 
     47 void test_small_hamming_distance(void)
     48 {
     49    TEST_ASSERT_EQUAL(1, compute("AT", "CT"));
     50 }
     51 
     52 void test_small_hamming_distance_in_longer_strand(void)
     53 {
     54    TEST_ASSERT_EQUAL(1, compute("GGACG", "GGTCG"));
     55 }
     56 
     57 void test_rejects_extra_length_on_first_strand_when_longer(void)
     58 {
     59    TEST_ASSERT_EQUAL(-1, compute("AAAG", "AAA"));
     60 }
     61 
     62 void test_rejects_extra_length_on_other_strand_when_longer(void)
     63 {
     64    TEST_ASSERT_EQUAL(-1, compute("AAA", "AAAG"));
     65 }
     66 
     67 void test_large_hamming_distance(void)
     68 {
     69    TEST_ASSERT_EQUAL(4, compute("GATACA", "GCATAA"));
     70 }
     71 
     72 void test_hamming_distance_in_very_long_strand(void)
     73 {
     74    TEST_ASSERT_EQUAL(9, compute("GGACGGATTCTG", "AGGACGGATTCT"));
     75 }
     76 
     77 int main(void)
     78 {
     79    UnityBegin("test/test_hamming.c");
     80 
     81    RUN_TEST(test_empty_strands);
     82    RUN_TEST(test_no_difference_between_identical_strands);
     83    RUN_TEST(test_rejects_null_strand);
     84    RUN_TEST(test_rejects_other_null_strand);
     85    RUN_TEST(test_identical_long_strands);
     86    RUN_TEST(test_hamming_distance_for_single_nucleotide_strand);
     87    RUN_TEST(test_complete_hamming_distance_for_small_strand);
     88    RUN_TEST(test_small_hamming_distance);
     89    RUN_TEST(test_small_hamming_distance_in_longer_strand);
     90    RUN_TEST(test_rejects_extra_length_on_first_strand_when_longer);
     91    RUN_TEST(test_rejects_extra_length_on_other_strand_when_longer);
     92    RUN_TEST(test_large_hamming_distance);
     93    RUN_TEST(test_hamming_distance_in_very_long_strand);
     94 
     95    return UnityEnd();
     96 }