OSDN Git Service

rename file name with specific name
authortsutsumi <>
Fri, 20 Aug 2010 07:18:43 +0000 (07:18 +0000)
committertsutsumi <>
Fri, 20 Aug 2010 07:18:43 +0000 (07:18 +0000)
examples/complex/runTestCase.c [new file with mode: 0644]
examples/complex/runTestCaseSetup.c [new file with mode: 0644]
examples/complex/runTestSuiteAuto.c [new file with mode: 0644]
examples/complex/testComplexArith.c [new file with mode: 0644]
examples/complex/testComplexSetup.c [new file with mode: 0644]

diff --git a/examples/complex/runTestCase.c b/examples/complex/runTestCase.c
new file mode 100644 (file)
index 0000000..db65415
--- /dev/null
@@ -0,0 +1,46 @@
+/* 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
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The CCUnit Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the CCUnit Library; see the file COPYING.LESSER.
+   If not, write to the Free Software Foundation, Inc., 59 Temple
+   Place - Suite 330, Boston, MA 02111-1307, USA.  
+*/
+
+/*
+ * $Id$
+ */
+
+#include <ccunit/CCUnit.h>
+
+extern void test_complex_new ();
+extern void test_complex_equals ();
+
+int main ()
+{
+  CCUnitTestCase* testCase;
+  CCUnitTestResult* result;
+  bool success;
+  testCase = ccunit_newTestCase ("complex test");
+  ccunit_addNewTestFunc (testCase,
+                         "test_complex_new",
+                         "test new",
+                         test_complex_new);
+  ccunit_addNewTestFunc (testCase, 
+                         "test_complex_equals",
+                         "complex equals test",
+                         test_complex_equals);
+  result = ccunit_runTestCase (testCase);
+  success = ccunit_wasSuccessful (result);
+  return success ? 0 : -1;
+}
diff --git a/examples/complex/runTestCaseSetup.c b/examples/complex/runTestCaseSetup.c
new file mode 100644 (file)
index 0000000..ccd70e9
--- /dev/null
@@ -0,0 +1,56 @@
+/* Copyright (C) 2003 TSUTSUMI Kikuo.
+   This file is part of the CCUnit Library.
+
+   The CCUnit Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The CCUnit Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the CCUnit Library; see the file COPYING.LESSER.
+   If not, write to the Free Software Foundation, Inc., 59 Temple
+   Place - Suite 330, Boston, MA 02111-1307, USA.  
+*/
+
+/*
+ * $Id$
+ */
+
+#include <ccunit/CCUnit.h>
+
+extern void setUp_test_complex ();
+extern void tearDown_test_complex ();
+extern void test_complex_new ();
+extern void test_complex_equals ();
+
+int main ()
+{
+  CCUnitTestCase* testCase;
+  CCUnitTestResult* result;
+  bool success;
+  testCase = ccunit_newTestCase ("complex test");
+  ccunit_addNewTestFunc (testCase,
+                         "setUp_test_complex",
+                         "setUp_test_complex",
+                         setUp_test_complex);
+  ccunit_addNewTestFunc (testCase, 
+                         "tearDown_test_complex",
+                         "tearDown_test_complex",
+                         tearDown_test_complex);
+  ccunit_addNewTestFunc (testCase,
+                         "test_complex_new",
+                         "test new",
+                         test_complex_new);
+  ccunit_addNewTestFunc (testCase, 
+                         "test_complex_equals",
+                         "complex equals test",
+                         test_complex_equals);
+  result = ccunit_runTestCase (testCase);
+  success = ccunit_wasSuccessful (result);
+  return success ? 0 : -1;
+}
diff --git a/examples/complex/runTestSuiteAuto.c b/examples/complex/runTestSuiteAuto.c
new file mode 100644 (file)
index 0000000..bcbc853
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright (C) 2010 TSUTSUMI Kikuo.
+   This file is part of the CCUnit Library.
+
+   The CCUnit Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The CCUnit Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the CCUnit Library; see the file COPYING.LESSER.
+   If not, see <http://www.gnu.org/licenses/>
+*/
+
+/*
+ * $Id$
+ */
+
+#include <ccunit/CCUnitTestSuite.h>
+
+extern CCUnitTestSuite* suite_test_complex (char* name);
+
+int main ()
+{
+  CCUnitTestSuite* suite;
+  CCUnitTestResult* result;
+  size_t num;
+  suite = suite_test_complex ("complex suite auto generated");
+  result = ccunit_runTestSuite (suite, NULL);
+  num = ccunit_failureCount (result);
+  return num;
+}
diff --git a/examples/complex/testComplexArith.c b/examples/complex/testComplexArith.c
new file mode 100644 (file)
index 0000000..59f249a
--- /dev/null
@@ -0,0 +1,87 @@
+/* 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
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The CCUnit Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the CCUnit Library; see the file COPYING.LESSER.
+   If not, see <http://www.gnu.org/licenses/>
+*/
+
+/*
+ * $Id$
+ */
+
+#include <ccunit/CCUnitAssert.h>
+
+/** TEST SUITE: complex arith test suite */
+
+/** TEST CASE: complex arith test */
+
+#include "complex.h"
+
+static complex_t* c6_3;
+static complex_t* c3_2;
+
+void setUp_test_complex_arith ()
+{
+  c6_3 = complex_new (6, 3);
+  c3_2 = complex_new (3, 2);
+}
+void tearDown_test_complex_arith ()
+{
+  complex_delete (c6_3);
+  complex_delete (c3_2);
+}
+
+/** test add */
+void test_complex_add ()
+{
+  complex_t ans = { 9, 5 };
+  complex_t result;
+  CCUNIT_ASSERT (complex_equals (&ans, complex_add (&result, c6_3, c3_2)));
+}
+
+/** test sub */
+void test_complex_sub ()
+{
+  complex_t ans = { 3, 1 };
+  complex_t result;
+  CCUNIT_ASSERT_TEST_OBJ (&ans, complex_equals,
+                         complex_sub (&result, c6_3, c3_2),
+                         complex_to_string);
+}
+
+/** test mul */
+void test_complex_mul ()
+{
+  complex_t* ans = complex_new (6*3 - 3*2, 6*2 + 3*3);
+  complex_t result;
+  CCUNIT_ASSERT_TEST_OBJ (ans, complex_equals,
+                         complex_mul (&result, c6_3, c3_2),
+                         complex_to_string);
+  complex_delete (ans);
+}
+
+/** test div */
+void test_complex_div ()
+{
+  const double r2 = 3*3 + 2*2;
+  complex_t* ans = complex_new ((6*3 + 3*2)/r2, (3*3 - 6*2)/r2);
+  complex_t result;
+  CCUNIT_ASSERT_TEST_OBJ (ans, complex_equals,
+                         complex_div (&result, c6_3, c3_2),
+                         complex_to_string);
+  complex_delete (ans);
+}
+
+/** end test case */
diff --git a/examples/complex/testComplexSetup.c b/examples/complex/testComplexSetup.c
new file mode 100644 (file)
index 0000000..8ad23c6
--- /dev/null
@@ -0,0 +1,70 @@
+/* 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
+   modify it under the terms of the GNU Lesser General Public License
+   as published by the Free Software Foundation; either version 2.1 of
+   the License, or (at your option) any later version.
+
+   The CCUnit Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the CCUnit Library; see the file COPYING.LESSER.
+   If not, write to the Free Software Foundation, Inc., 59 Temple
+   Place - Suite 330, Boston, MA 02111-1307, USA.  
+*/
+
+/*
+ * $Id$
+ */
+
+#include <ccunit/CCUnitAssert.h>
+
+#include <complex.h>
+
+/** TEST CASE: complex number add test */
+
+static complex_t* c10_1;
+
+void setUp_test_complex ()
+{
+  c10_1 = complex_new (10, 1);
+}
+
+void tearDown_test_complex ()
+{
+  complex_delete (c10_1);
+}
+
+/** test new */
+void test_complex_new ()
+{
+  CCUNIT_ASSERT_TEST (double, 10, ==, c10_1->real);
+  CCUNIT_ASSERT_TEST (double, 1, ==, c10_1->imaginary);
+}
+
+/** test equals */
+void test_complex_equals ()
+{
+  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_2);
+  complex_delete (c1_1);
+}
+
+/** test to_string */
+void test_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 */