Last active
December 11, 2015 12:19
-
-
Save hoodja/4600266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "unity_fixture.h" | |
int PrimeFactors(int number, int* primes, int primes_size) | |
{ | |
int count = 0; | |
int candidate = 0; | |
for (candidate = 2; number > 1; candidate++) | |
for (; number % candidate == 0; number /= candidate) | |
primes[count++] = candidate; | |
return count; | |
} | |
const int MAX_ITEMS = 100; | |
int expected[100] = {0}; | |
int actual[100] = {0}; | |
TEST_GROUP(PrimeFactors); | |
TEST_SETUP(PrimeFactors) | |
{ | |
} | |
TEST_TEAR_DOWN(PrimeFactors) | |
{ | |
} | |
TEST(PrimeFactors, testOne) | |
{ | |
int size = PrimeFactors(1, actual, 100); | |
TEST_ASSERT_EQUAL(0, size); | |
} | |
TEST(PrimeFactors, testTwo) | |
{ | |
int size = PrimeFactors(2, actual, 100); | |
expected[0] = 2; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 1); | |
} | |
TEST(PrimeFactors, testThree) | |
{ | |
int size = PrimeFactors(3, actual, 100); | |
expected[0] = 3; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 1); | |
} | |
TEST(PrimeFactors, testFour) | |
{ | |
int size = PrimeFactors(4, actual, 100); | |
expected[0] = 2; | |
expected[1] = 2; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 2); | |
} | |
TEST(PrimeFactors, testSix) | |
{ | |
int size = PrimeFactors(6, actual, 100); | |
expected[0] = 2; | |
expected[1] = 3; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 2); | |
} | |
TEST(PrimeFactors, testEight) | |
{ | |
int size = PrimeFactors(8, actual, 100); | |
expected[0] = 2; | |
expected[1] = 2; | |
expected[2] = 2; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 3); | |
} | |
TEST(PrimeFactors, testNine) | |
{ | |
int size = PrimeFactors(9, actual, 100); | |
expected[0] = 3; | |
expected[1] = 3; | |
TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, 2); | |
} | |
TEST_GROUP_RUNNER(PrimeFactors) | |
{ | |
RUN_TEST_CASE(PrimeFactors, testOne); | |
RUN_TEST_CASE(PrimeFactors, testTwo); | |
RUN_TEST_CASE(PrimeFactors, testThree); | |
RUN_TEST_CASE(PrimeFactors, testFour); | |
RUN_TEST_CASE(PrimeFactors, testSix); | |
RUN_TEST_CASE(PrimeFactors, testEight); | |
RUN_TEST_CASE(PrimeFactors, testNine); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment