BaseTest.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /***************************************************************************
  2. BaseTest.h - description
  3. -------------------
  4. begin : Sun Aug 25 2002
  5. copyright : (C) 2002 by Henrik Enqvist
  6. email : henqvist@excite.com
  7. ***************************************************************************/
  8. /****************************************************************************
  9. * Unit testing
  10. ***************************************************************************/
  11. #ifndef BASETEST_H
  12. #define BASETEST_H
  13. #if EM_UNIT_TEST
  14. #include "EMath.h"
  15. #include "Shape3D.h"
  16. #include "Polygon.h"
  17. #include <cppunit/TestFixture.h>
  18. #include <cppunit/Test.h>
  19. #include <cppunit/TestSuite.h>
  20. #include <cppunit/TestCaller.h>
  21. #include <cppunit/extensions/HelperMacros.h>
  22. class EMathTest : public CppUnit::TestFixture {
  23. public:
  24. void setUp() {
  25. }
  26. void tearDown() {
  27. }
  28. void testTrigonometry() {
  29. }
  30. void testInterpolation() {
  31. }
  32. CPPUNIT_TEST_SUITE(EMathTest);
  33. CPPUNIT_TEST(testTrigonometry);
  34. CPPUNIT_TEST(testInterpolation);
  35. CPPUNIT_TEST_SUITE_END();
  36. };
  37. class ShapeTest : public CppUnit::TestFixture {
  38. private:
  39. Shape3D * shape;
  40. Polygon3D * poly;
  41. public:
  42. void setUp() {
  43. shape = new Shape3D();
  44. shape->add(0,0,0, 0,0,0,0, 0,0);
  45. shape->add(0,0,0, 0,0,0,0, 0,0);
  46. shape->add(0,0,0, 0,0,0,0, 0,0);
  47. shape->add(0,0,0, 0,0,0,0, 0,0);
  48. shape->add(0,0,0, 0,0,0,0, 0,0);
  49. shape->add(0,0,0, 0,0,0,0, 0,0);
  50. poly = new Polygon3D(shape);
  51. poly->add(1);
  52. poly->add(2);
  53. poly->add(4);
  54. poly->add(3);
  55. }
  56. void tearDown() {
  57. delete poly;
  58. delete shape;
  59. }
  60. void testIndex() {
  61. CPPUNIT_ASSERT(poly->getIndex(0) == 1);
  62. CPPUNIT_ASSERT(poly->getIndex(1) == 2);
  63. CPPUNIT_ASSERT(poly->getIndex(2) == 4);
  64. CPPUNIT_ASSERT(poly->getIndex(3) == 3);
  65. }
  66. void testIncludes() {
  67. CPPUNIT_ASSERT(poly->includes(0) == -1);
  68. CPPUNIT_ASSERT(poly->includes(1) == 0);
  69. CPPUNIT_ASSERT(poly->includes(2) == 1);
  70. CPPUNIT_ASSERT(poly->includes(3) == 3);
  71. CPPUNIT_ASSERT(poly->includes(4) == 2);
  72. CPPUNIT_ASSERT(poly->includes(5) == -1);
  73. }
  74. void testConnected() {
  75. CPPUNIT_ASSERT(poly->connected(1,2) == true);
  76. CPPUNIT_ASSERT(poly->connected(2,1) == true);
  77. CPPUNIT_ASSERT(poly->connected(2,4) == true);
  78. CPPUNIT_ASSERT(poly->connected(4,3) == true);
  79. CPPUNIT_ASSERT(poly->connected(1,3) == true);
  80. CPPUNIT_ASSERT(poly->connected(1,0) == false);
  81. CPPUNIT_ASSERT(poly->connected(0,2) == false);
  82. CPPUNIT_ASSERT(poly->connected(1,4) == false);
  83. }
  84. CPPUNIT_TEST_SUITE(ShapeTest);
  85. CPPUNIT_TEST(testIndex);
  86. CPPUNIT_TEST(testIncludes);
  87. CPPUNIT_TEST(testConnected);
  88. CPPUNIT_TEST_SUITE_END();
  89. };
  90. #endif //EM_UNIT_TEST
  91. #endif // EMATH_H