A C Unit Test Library for C language.
Revisión | 6a47784aa4074fbd1bad49627b9f25a03b978c8b (tree) |
---|---|
Tiempo | 2013-07-06 17:31:15 |
Autor | tsntsumi <tsntsumi@user...> |
Commiter | tsntsumi |
Modified the example the test fails.
@@ -369,12 +369,12 @@ of @c testComplex.c on purpose. | ||
369 | 369 | @endif |
370 | 370 | |
371 | 371 | @code |
372 | -void test_complex_equals () | |
372 | +void test_complex_new () | |
373 | 373 | { |
374 | 374 | ... |
375 | - CCUNIT_ASSERT (complex_equals (c10_1, c10_1_2)); | |
376 | -/*CCUNIT_ASSERT (complex_equals (c10_1, c1_1) == 0);*/ | |
377 | - CCUNIT_ASSERT (complex_equals (c10_1, c1_1) != 0); | |
375 | + CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real); | |
376 | +/*CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);*/ | |
377 | + CCUNIT_ASSERT_EQ_DOUBLE (1.1, c10_1->imaginary); | |
378 | 378 | ... |
379 | 379 | } |
380 | 380 | @endcode |
@@ -382,15 +382,17 @@ void test_complex_equals () | ||
382 | 382 | @code |
383 | 383 | $ gcc -o runTestCaseRunner runTestCaseRunner.c testComplex.c complex.c -lccunit |
384 | 384 | $ ./runTestRunner |
385 | -..F | |
386 | -Time: 0.000036 sec | |
385 | +.F. | |
386 | +Time: 0.000051 sec | |
387 | 387 | |
388 | 388 | FAILURES!!! |
389 | 389 | Test Results: |
390 | 390 | Run 2, Failures 1 |
391 | 391 | There was 1 failure: |
392 | -testComplex.c:46: complex equals test: | |
393 | - complex_equals (c10_1, c1_1) != 0 | |
392 | +testFailComplex.c:36: complex new test: | |
393 | + 1.1 == c10_1->imaginary | |
394 | + expect: 1.100000 | |
395 | + actual: 1.000000 | |
394 | 396 | @endcode |
395 | 397 | |
396 | 398 | @english |
@@ -399,12 +401,12 @@ Then, you will see that the second is unsuccessful. | ||
399 | 401 | @japanese |
400 | 402 | この例ではテストケースを 2 個実行して、 |
401 | 403 | ひとつのテストケースで失敗していることがわかります。 |
402 | -最初の「<code>..F</code>」では、 | |
403 | -ふたつ目のテストケースが失敗していることをあらわしています。 | |
404 | +最初の「 <code>.F.</code>」では、 | |
405 | +ひとつ目のテストケースが失敗していることをあらわしています。 | |
404 | 406 | |
405 | 407 | また上述のように、 |
406 | -失敗したファイル名、行番号、テストケースの名前 (<code>complex equals test</code>)、 | |
407 | -表明した条件の文字列 (<code>complex_equals (c10_1, c1_1) != 0</code>) が表示されます。 | |
408 | +失敗したファイル名、行番号、テストケースの名前 (<code>complex new test</code>)、 | |
409 | +表明した条件の文字列 (<code>1.1 == c10_1->imaginary</code>) が表示されます。 | |
408 | 410 | @endif |
409 | 411 | |
410 | 412 | @english |
@@ -877,7 +879,7 @@ One file can define the multiple test case. | ||
877 | 879 | |
878 | 880 | static complex_t* c10_1; |
879 | 881 | |
880 | -//** test new *\/ | |
882 | +//** complex new test *\/ | |
881 | 883 | void test_complex_new () |
882 | 884 | { |
883 | 885 | ... |
@@ -12,5 +12,6 @@ runTestFixture | ||
12 | 12 | runTestRunner |
13 | 13 | runTestSuite |
14 | 14 | runTestSuiteAuto |
15 | +runTestFailComplex | |
15 | 16 | suiteComplex.c |
16 | 17 | suiteTestComplex.c |
@@ -24,6 +24,7 @@ check_PROGRAMS = runTestCase runTestCaseRunner runTestCaseSetup \ | ||
24 | 24 | runTestSuite runTestSuiteAuto |
25 | 25 | TESTS = runTestCase runTestCaseRunner runTestCaseSetup \ |
26 | 26 | runTestSuite runTestSuiteAuto |
27 | +noinst_PROGRAMS = runTestFailComplex | |
27 | 28 | |
28 | 29 | libcomplex_a_SOURCES = complex.c complex.h |
29 | 30 |
@@ -41,11 +42,13 @@ runTestSuiteAuto_SOURCES = runTestSuiteAuto.c testComplexSetup.c testComplexArit | ||
41 | 42 | nodist_runTestSuiteAuto_SOURCES = suiteTestComplex.c |
42 | 43 | BUILT_SOURCES = suiteTestComplex.c |
43 | 44 | |
45 | +runTestFailComplex_SOURCES = runTestCaseRunner.c testFailComplex.c | |
46 | + | |
44 | 47 | AM_CFLAGS=-Wall -Werror |
45 | 48 | AM_CPPFLAGS=-I. -I$(top_srcdir)/src -I$(top_builddir)/src |
46 | 49 | AM_LDFLAGS=-L. -L$(top_builddir)/src/ccunit |
47 | 50 | |
48 | -EXTRA_DIST= | |
51 | +EXTRA_DIST=testFailComplex.c | |
49 | 52 | |
50 | 53 | CLEANFILES=*~ .*~ ./\#*\# *.log suiteTestComplex.c |
51 | 54 |
@@ -35,7 +35,7 @@ int main () | ||
35 | 35 | testCase = ccunit_newTestCase ("complex test"); |
36 | 36 | ccunit_addNewTestFunc (testCase, |
37 | 37 | "test_complex_new", |
38 | - "test new", | |
38 | + "complex new test", | |
39 | 39 | test_complex_new); |
40 | 40 | ccunit_addNewTestFunc (testCase, |
41 | 41 | "test_complex_equals", |
@@ -36,7 +36,7 @@ int main () | ||
36 | 36 | testCase = ccunit_newTestCase ("complex test"); |
37 | 37 | ccunit_addNewTestFunc (testCase, |
38 | 38 | "test_complex_new", |
39 | - "test new", | |
39 | + "complex new test", | |
40 | 40 | test_complex_new); |
41 | 41 | ccunit_addNewTestFunc (testCase, |
42 | 42 | "test_complex_equals", |
@@ -27,16 +27,16 @@ | ||
27 | 27 | |
28 | 28 | /** TEST CASE: complex number add test */ |
29 | 29 | |
30 | -/** test new */ | |
30 | +/** complex new test */ | |
31 | 31 | void test_complex_new () |
32 | 32 | { |
33 | 33 | complex_t* c10_1 = complex_new (10, 1); |
34 | - CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real); | |
35 | - CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary); | |
34 | + CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real); | |
35 | + CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary); | |
36 | 36 | complex_delete (c10_1); |
37 | 37 | } |
38 | 38 | |
39 | -/** test equals */ | |
39 | +/** complex equals test */ | |
40 | 40 | void test_complex_equals () |
41 | 41 | { |
42 | 42 | complex_t* c10_1 = complex_new (10, 1); |
@@ -49,7 +49,7 @@ void test_complex_equals () | ||
49 | 49 | complex_delete (c1_1); |
50 | 50 | } |
51 | 51 | |
52 | -/** test to_string */ | |
52 | +/** complex to_string test */ | |
53 | 53 | void test_complex_to_string () |
54 | 54 | { |
55 | 55 | complex_t* c10_1 = complex_new (10, 1); |
@@ -42,8 +42,8 @@ void tearDown_test_complex () | ||
42 | 42 | /** test new */ |
43 | 43 | void test_complex_new () |
44 | 44 | { |
45 | - CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real); | |
46 | - CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary); | |
45 | + CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real); | |
46 | + CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary); | |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** test equals */ |
@@ -0,0 +1,63 @@ | ||
1 | +/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo. | |
2 | + This file is part of the CCUnit Library. | |
3 | + | |
4 | + The CCUnit Library is free software; you can redistribute it and/or | |
5 | + modify it under the terms of the GNU Lesser General Public License | |
6 | + as published by the Free Software Foundation; either version 2.1 of | |
7 | + the License, or (at your option) any later version. | |
8 | + | |
9 | + The CCUnit Library is distributed in the hope that it will be | |
10 | + useful, but WITHOUT ANY WARRANTY; without even the implied warranty | |
11 | + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | + GNU Lesser General Public License for more details. | |
13 | + | |
14 | + You should have received a copy of the GNU Lesser General Public | |
15 | + License along with the CCUnit Library; see the file COPYING.LESSER. | |
16 | + If not, write to the Free Software Foundation, Inc., 59 Temple | |
17 | + Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | +*/ | |
19 | + | |
20 | +/* | |
21 | + * $Id$ | |
22 | + */ | |
23 | + | |
24 | +#include <ccunit/CCUnitAssert.h> | |
25 | + | |
26 | +#include "complex.h" | |
27 | + | |
28 | +/** TEST CASE: complex number add test */ | |
29 | + | |
30 | +/** complex new test */ | |
31 | +void test_complex_new () | |
32 | +{ | |
33 | + complex_t* c10_1 = complex_new (10, 1); | |
34 | + CCUNIT_ASSERT_EQ_DOUBLE (10, c10_1->real); | |
35 | +/*CCUNIT_ASSERT_EQ_DOUBLE (1, c10_1->imaginary);*/ | |
36 | + CCUNIT_ASSERT_EQ_DOUBLE (1.1, c10_1->imaginary); | |
37 | + complex_delete (c10_1); | |
38 | +} | |
39 | + | |
40 | +/** complex equals test */ | |
41 | +void test_complex_equals () | |
42 | +{ | |
43 | + complex_t* c10_1 = complex_new (10, 1); | |
44 | + complex_t* c10_1_2 = complex_new (10, 1); | |
45 | + complex_t* c1_1 = complex_new (1, 1); | |
46 | + CCUNIT_ASSERT (complex_equals (c10_1, c10_1_2)); | |
47 | + CCUNIT_ASSERT (complex_equals (c10_1, c1_1) == 0); | |
48 | + complex_delete (c10_1); | |
49 | + complex_delete (c10_1_2); | |
50 | + complex_delete (c1_1); | |
51 | +} | |
52 | + | |
53 | +/** complex to_string test */ | |
54 | +void test_complex_to_string () | |
55 | +{ | |
56 | + complex_t* c10_1 = complex_new (10, 1); | |
57 | + char* s10_1 = complex_to_string (c10_1); | |
58 | + CCUNIT_ASSERT_EQ_STR ("10+1i", s10_1); | |
59 | + complex_delete (c10_1); | |
60 | + free (s10_1); | |
61 | +} | |
62 | + | |
63 | +/** end test case */ |