--- /dev/null
+
+Makefile
+Makefile.in
--- /dev/null
+## Process this file with automake to produce Makefile.in
+## 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$
+
+SUBDIRS = complex
--- /dev/null
+## Process this file with automake to produce Makefile.in
+## 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$
+
+lib_LIBRARIES = libcomplex.a
+check_PROGRAMS = runTestFixture runTestSuite runTestRunner runTest
+TESTS = runTestFixture runTestSuite runTestRunner runTest
+
+libcomplex_a_SOURCES = complex.c complex.h
+runTest_SOURCES = runTest.c testComplex.c testComplexMulDiv.c
+runTest_LDADD = -lcomplex -lccunit
+nodist_runTest_SOURCES = suiteComplex.c
+BUILT_SOURCES = suiteComplex.c
+
+runTestFixture_SOURCES = runTestFixture.c testComplex.c
+runTestFixture_LDADD = -lcomplex -lccunit
+
+runTestSuite_SOURCES = runTestSuite.c testComplexMulDiv.c testComplex.c \
+ complexTestSuite.c
+runTestSuite_LDADD = -lcomplex -lccunit
+
+runTestRunner_SOURCES = runTestRunner.c testComplexMulDiv.c testComplex.c \
+ complexTestSuite.c
+runTestRunner_LDADD = -lcomplex -lccunit
+
+AM_CFLAGS=-Wall -Werror
+AM_CPPFLAGS=-I. -I$(top_srcdir)/src
+AM_LDFLAGS=-L. -L$(top_srcdir)/src/ccunit
+
+EXTRA_DIST=
+
+CLEANFILES=*~ .*~ ./\#*\# *.log suiteComplex.c
+
+MAKESUITE=$(top_srcdir)/src/tools/ccunit_makeSuite
+
+suiteComplex.c: testComplex.c
+ $(MAKESUITE) -f complex_suite -o $@ $+
--- /dev/null
+/* 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 <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "complex.h"
+
+complex_t* complex_new (double real, double imaginary)
+{
+ complex_t* cp = calloc (1, sizeof (complex_t));
+ if (!cp)
+ return NULL;
+ cp->real = real;
+ cp->imaginary = imaginary;
+ return cp;
+}
+
+inline void complex_delete (const complex_t* cp)
+{
+ free ((complex_t*)cp);
+}
+
+char* complex_to_string (const complex_t* cp)
+{
+ char* str = calloc (40, sizeof (char));
+ snprintf (str, 40, "%g%+gi", cp->real, cp->imaginary);
+ return str;
+}
+
+complex_t* complex_add (complex_t* z, const complex_t* x, const complex_t* y)
+{
+ z->real = x->real + y->real;
+ z->imaginary = x->imaginary + y->imaginary;
+ return z;
+}
+
+complex_t* complex_sub (complex_t* z, const complex_t* x, const complex_t* y)
+{
+ z->real = x->real - y->real;
+ z->imaginary = x->imaginary - y->imaginary;
+ return z;
+}
+
+complex_t* complex_mul (complex_t* z, const complex_t* x, const complex_t* y)
+{
+ complex_t c;
+ c.real = x->real * y->real - x->imaginary * y->imaginary;
+ c.imaginary = x->real * y->imaginary + x->imaginary * y->real;
+ *z = c;
+ return z;
+}
+
+complex_t* complex_div (complex_t* z, const complex_t* x, const complex_t* y)
+{
+ const double r2 = y->real * y->real + y->imaginary * y->imaginary;
+ complex_t c;
+ c.real = (x->real * y->real + x->imaginary * y->imaginary) / r2;
+ c.imaginary = (x->imaginary * y->real - x->real * y->imaginary) / r2;
+ *z = c;
+ return z;
+}
+
+inline int complex_equals (const complex_t*x, const complex_t* y)
+{
+ return x->real == y->real && x->imaginary == y->imaginary;
+}
--- /dev/null
+/* -*- C -*- */
+/* 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$
+ */
+
+#ifndef COMPLEX_H
+#define COMPLEX_H
+
+typedef struct complex_t
+{
+ double real;
+ double imaginary;
+} complex_t;
+
+extern complex_t* complex_new (double real, double imaginary);
+extern inline void complex_delete (const complex_t* cp);
+extern char* complex_to_string (const complex_t* cp);
+extern complex_t* complex_add (complex_t* z, const complex_t* x, const complex_t* y);
+extern complex_t* complex_sub (complex_t* z, const complex_t* x, const complex_t* y);
+extern complex_t* complex_mul (complex_t* z, const complex_t* x, const complex_t* y);
+extern complex_t* complex_div (complex_t* z, const complex_t* x, const complex_t* y);
+extern inline int complex_equals (const complex_t*x, const complex_t* y);
+
+#endif /* COMPLEX_H */
--- /dev/null
+/* 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/CCUnitTestSuite.h>
+
+void setUp_complex_test ();
+void tearDown_complex_test ();
+void test_complex_equals ();
+void test_complex_add ();
+void test_complex_sub ();
+
+void setUp_complex_mul_div ();
+void tearDown_complex_mul_div ();
+void test_complex_mul ();
+void test_complex_div ();
+
+CCUnitTestSuite* complex_add_sub_suite ()
+{
+ CCUnitTestFixture* fixture;
+ CCUnitTestSuite* suite;
+ fixture = ccunit_newTestFixture ("complex add sub test",
+ CCUNIT_NEWTESTFUNC(setUp_complex_test),
+ CCUNIT_NEWTESTFUNC(tearDown_complex_test));
+ ccunit_addNewTestCase (fixture,
+ "test_complex_equals",
+ "complex equals test",
+ test_complex_equals);
+ ccunit_addNewTestCase (fixture,
+ "test_complex_add",
+ "complex add test",
+ test_complex_add);
+ ccunit_addNewTestCase (fixture,
+ "test_complex_sub",
+ "complex sub test",
+ test_complex_sub);
+ suite = ccunit_newTestSuite ("complex add/sub test");
+ ccunit_addTestFixture (suite, fixture);
+ return suite;
+}
+
+CCUnitTestSuite* complex_mul_div_suite ()
+{
+ CCUnitTestFixture* fixture;
+ CCUnitTestSuite* suite;
+ fixture = ccunit_newTestFixture ("complex mul div test",
+ CCUNIT_NEWTESTFUNC(setUp_complex_mul_div),
+ CCUNIT_NEWTESTFUNC(tearDown_complex_mul_div));
+ ccunit_addNewTestCase (fixture,
+ "test_complex_mul",
+ "complex mul test",
+ test_complex_mul);
+ ccunit_addNewTestCase (fixture,
+ "test_complex_div",
+ "complex div test",
+ test_complex_div);
+ suite = ccunit_newTestSuite ("complex mul/div test");
+ ccunit_addTestFixture (suite, fixture);
+ return suite;
+}
--- /dev/null
+/* 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 <stdio.h>
+#include <ccunit/CCUnitTestRunner.h>
+#include <ccunit/CCUnitTestSuite.h>
+
+extern CCUnitTestSuite* complex_suite (const char* name);
+
+int main ()
+{
+ CCUnitTestRunner* runner;
+ CCUnitTestSuite* suite;
+ runner = ccunit_newTestRunner (stdout);
+ suite = complex_suite ("complex test suite");
+ return ccunit_runTestRunner (runner, suite);
+}
--- /dev/null
+/* 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_complex_test();
+extern void tearDown_complex_test();
+extern void test_complex_equals();
+extern void test_complex_add();
+
+int main ()
+{
+ CCUnitTestFixture* fixture;
+ CCUnitTestResult* result;
+ bool success;
+ fixture = ccunit_newTestFixture ("complex test",
+ CCUNIT_NEWTESTFUNC(setUp_complex_test),
+ CCUNIT_NEWTESTFUNC(tearDown_complex_test));
+ ccunit_addNewTestCase (fixture,
+ "test_complex_equals",
+ "complex equals test",
+ test_complex_equals);
+ ccunit_addNewTestCase (fixture,
+ "test_complex_add",
+ "complex add test",
+ test_complex_add);
+ result = ccunit_runTestFixture (fixture);
+ success = ccunit_wasSuccessful (result);
+ return success ? 0 : -1;
+}
--- /dev/null
+/* 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 <stdio.h>
+#include <ccunit/CCUnit.h>
+
+extern CCUnitTestSuite* complex_add_sub_suite ();
+extern CCUnitTestSuite* complex_mul_div_suite ();
+
+int main ()
+{
+ CCUnitTestRunner* runner;
+ CCUnitTestSuite* suite;
+ suite = ccunit_newTestSuite ("suite");
+ ccunit_addTestSuite (suite, complex_add_sub_suite ());
+ ccunit_addTestSuite (suite, complex_mul_div_suite ());
+ runner = ccunit_newTestRunner (stdout);
+ return ccunit_runTestRunner (runner, suite);
+}
--- /dev/null
+/* 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>
+
+CCUnitTestSuite* complex_add_sub_suite ();
+CCUnitTestSuite* complex_mul_div_suite ();
+
+int main ()
+{
+ CCUnitTestSuite* suite;
+ CCUnitTestResult* result;
+ bool success;
+ suite = ccunit_newTestSuite ("suite");
+ ccunit_addTestSuite (suite, complex_add_sub_suite ());
+ ccunit_addTestSuite (suite, complex_mul_div_suite ());
+ result = ccunit_runTestSuite (suite, NULL);
+ success = ccunit_wasSuccessful (result);
+ return success ? 0 : -1;
+}
--- /dev/null
+/* 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/CCUnitAssert.h>
+
+/** TEST CASE: complex number test */
+
+#include <complex.h>
+
+static complex_t* s10_1;
+static complex_t* s1_1;
+static complex_t* s11_2;
+
+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 ()
+{
+ complex_delete (s10_1);
+ complex_delete (s1_1);
+ complex_delete (s11_2);
+}
+
+/** 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)));
+}
+
+/** test sub */
+void test_complex_sub ()
+{
+ 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);
+}
+
+/** end test case */
--- /dev/null
+/* 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/CCUnitAssert.h>
+
+/** TEST SUITE: complex mul div test suite */
+
+/** TEST CASE: complex number mul/div test */
+
+#include <complex.h>
+
+static complex_t* s6_3;
+static complex_t* s3_2;
+static complex_t* smul;
+static complex_t* sdiv;
+
+void setUp_complex_mul_div ()
+{
+ const double r2 = 3*3 + 2*2;
+ s6_3 = complex_new (6, 3);
+ s3_2 = complex_new (3, 2);
+ smul = complex_new (6*3 - 3*2, 6*2 + 3*3);
+ sdiv = complex_new ((6*3 + 3*2)/r2, (3*3 - 6*2)/r2);
+}
+
+void tearDown_complex_mul_div ()
+{
+ complex_delete (s6_3);
+ complex_delete (s3_2);
+ complex_delete (smul);
+ complex_delete (sdiv);
+}
+
+void test_complex_mul ()
+{
+ complex_t result;
+ CCUNIT_ASSERT_TEST_OBJ (smul, complex_equals,
+ complex_mul (&result, s6_3, s3_2),
+ complex_to_string);
+}
+
+void test_complex_div ()
+{
+ complex_t result;
+ CCUNIT_ASSERT_TEST_OBJ (sdiv, complex_equals,
+ complex_div (&result, s6_3, s3_2),
+ complex_to_string);
+}