summary refs log tree commit diff stats
path: root/c/hamming/test/test_hamming.c
blob: c2a8bb45e1ea1ec6162a37233e003a704f4ba95c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "vendor/unity.h"
#include "../src/hamming.h"

void setUp(void)
{
}

void tearDown(void)
{
}

static void test_empty_strands(void)
{
   TEST_ASSERT_EQUAL(0, compute("", ""));
}

static void test_single_identical_strands(void)
{
   TEST_ASSERT_EQUAL(0, compute("A", "A"));
}

static void test_single_letter_different_strands(void)
{
   TEST_ASSERT_EQUAL(1, compute("G", "T"));
}

static void test_long_identical_strands(void)
{
   TEST_ASSERT_EQUAL(0, compute("GGACTGAAATCTG", "GGACTGAAATCTG"));
}

static void test_long_different_strands(void)
{
   TEST_ASSERT_EQUAL(9, compute("GGACGGATTCTG", "AGGACGGATTCT"));
}

static void test_disallow_first_strand_when_longer(void)
{
   TEST_ASSERT_EQUAL(-1, compute("AATG", "AAA"));
}

static void test_disallow_second_strand_when_longer(void)
{
   TEST_ASSERT_EQUAL(-1, compute("ATA", "AGTG"));
}

int main(void)
{
   UnityBegin("test/test_hamming.c");

   RUN_TEST(test_empty_strands);
   RUN_TEST(test_single_identical_strands);
   RUN_TEST(test_single_letter_different_strands);
   RUN_TEST(test_long_identical_strands);
   RUN_TEST(test_long_different_strands);
   RUN_TEST(test_disallow_first_strand_when_longer);
   RUN_TEST(test_disallow_second_strand_when_longer);

   return UnityEnd();
}