From f696854baa5794fe11f2443073f2d7a39d83127f Mon Sep 17 00:00:00 2001 From: tsntsumi Date: Fri, 20 Aug 2010 07:22:46 +0000 Subject: [PATCH] make simple --- examples/complex/testComplex.c | 59 ++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/examples/complex/testComplex.c b/examples/complex/testComplex.c index 915cbe8..6670c0d 100644 --- a/examples/complex/testComplex.c +++ b/examples/complex/testComplex.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 TSUTSUMI Kikuo. +/* Copyright (C) 2003, 2010 TSUTSUMI Kikuo. This file is part of the CCUnit Library. The CCUnit Library is free software; you can redistribute it and/or @@ -23,53 +23,40 @@ #include -/** TEST CASE: complex number test */ - #include -static complex_t* s10_1; -static complex_t* s1_1; -static complex_t* s11_2; +/** TEST CASE: complex number add test */ -void setUp_complex_test () -{ - s10_1 = complex_new (10, 1); - s1_1 = complex_new (1, 1); - s11_2 = complex_new (11, 2); -} - -void tearDown_complex_test () +/** test new */ +void test_complex_new () { - complex_delete (s10_1); - complex_delete (s1_1); - complex_delete (s11_2); + complex_t* c10_1 = complex_new (10, 1); + CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real); + CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary); + complex_delete (c10_1); } /** test equals */ void test_complex_equals () { - CCUNIT_ASSERT_TEST_OBJ (s10_1, complex_equals, s10_1, complex_to_string); - CCUNIT_ASSERT_TEST_OBJ (s10_1, !complex_equals, s1_1, complex_to_string); -} - -/** test add */ -void test_complex_add () -{ - complex_t c10_1 = { 10.0, 1.0 }; - complex_t c1_1 = { 1.0, 1.0 }; - complex_t result; - complex_t c11_2 = { 11.0, 2.0 }; - CCUNIT_ASSERT (complex_equals (&c11_2, complex_add (&result, &c10_1, &c1_1))); + complex_t* c10_1 = complex_new (10, 1); + complex_t* c10_1_2 = complex_new (10, 1); + complex_t* c1_1 = complex_new (1, 1); + CCUNIT_ASSERT_TEST_OBJ (c10_1, complex_equals, c10_1_2, complex_to_string); + CCUNIT_ASSERT_TEST_OBJ (c10_1, !complex_equals, c1_1, complex_to_string); + complex_delete (c10_1); + complex_delete (c10_1_2); + complex_delete (c1_1); } -/** test sub */ -void test_complex_sub () +/** test to_string */ +void test_complex_to_string () { - complex_t c9_0 = { 9, 0 }; - complex_t result; - CCUNIT_ASSERT_TEST_OBJ (&c9_0, complex_equals, - complex_sub (&result, s10_1, s1_1), - complex_to_string); + complex_t* c10_1 = complex_new (10, 1); + char* s10_1 = complex_to_string (c10_1); + CCUNIT_ASSERT_EQ_STR ("10+1i", s10_1); + complex_delete (c10_1); + free (s10_1); } /** end test case */ -- 2.11.0