00001 #ifndef Impala_Core_Array_TestEquals_h
00002 #define Impala_Core_Array_TestEquals_h
00003
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include "Core/Array/MakeRandom.h"
00006 #include "Core/Array/MakeFromValue.h"
00007 #include "Core/Array/Equals.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Array
00014 {
00015
00016 class TestEquals : public CPPUNIT_NS::TestFixture
00017 {
00018 CPPUNIT_TEST_SUITE(TestEquals);
00019 CPPUNIT_TEST(testSize);
00020 CPPUNIT_TEST(testData);
00021 CPPUNIT_TEST(testTolerance);
00022 CPPUNIT_TEST_SUITE_END();
00023
00024 public:
00025
00026 void
00027 testSize()
00028 {
00029
00030 Array2dScalarReal64* a = MakeFromValue<Array2dScalarReal64>(0.0, 1, 2, 0, 0);
00031 Array2dScalarReal64* b = MakeFromValue<Array2dScalarReal64>(0.0, 1, 2, 0, 0);
00032 CPPUNIT_ASSERT(Equals(a, b));
00033 CPPUNIT_ASSERT(Equals(a, a));
00034
00035 Array2dScalarReal64* c = MakeFromValue<Array2dScalarReal64>(0.0, 1, 2, 2, 2);
00036 CPPUNIT_ASSERT(Equals(a, c));
00037 CPPUNIT_ASSERT(Equals(c, c));
00038
00039 Array2dScalarReal64* d = MakeFromValue<Array2dScalarReal64>(0.0, 3, 2, 2, 2);
00040 CPPUNIT_ASSERT(!Equals(a, d));
00041
00042
00043 Array2dScalarReal64* e = MakeFromValue<Array2dScalarReal64>(0.0, 0, 0, 0, 0);
00044 Array2dScalarReal64* f = MakeFromValue<Array2dScalarReal64>(1.0, 0, 0, 0, 0);
00045 CPPUNIT_ASSERT(Equals(e, f));
00046
00047 Array2dScalarReal64* g = MakeFromValue<Array2dScalarReal64>(2.0, 0, 0, 1, 2);
00048 CPPUNIT_ASSERT(Equals(e, g));
00049
00050 CPPUNIT_ASSERT(!Equals(a, e));
00051 CPPUNIT_ASSERT(!Equals(a, g));
00052
00053 }
00054
00055 void
00056 testData()
00057 {
00058
00059 Array2dScalarReal64* a = MakeFromValue<Array2dScalarReal64>(0.0, 4, 4, 0, 0);
00060 Array2dScalarReal64* b = MakeFromValue<Array2dScalarReal64>(0.0, 4, 4, 0, 0);
00061 CPPUNIT_ASSERT(Equals(a, b));
00062 CPPUNIT_ASSERT(Equals(a, a));
00063 Array2dScalarReal64* c = MakeFromValue<Array2dScalarReal64>(1.0, 4, 4, 0, 0);
00064 CPPUNIT_ASSERT(!Equals(a, c));
00065
00066
00067 b->CPB()[6] = 3.;
00068 CPPUNIT_ASSERT(Equals(b, b));
00069 CPPUNIT_ASSERT(!Equals(a, b));
00070
00071 Array2dScalarReal64* d = MakeFromValue<Array2dScalarReal64>(0.0, 4, 4, 1, 1);
00072 CPPUNIT_ASSERT(Equals(a, d));
00073 d->PB()[0] = 3.;
00074 CPPUNIT_ASSERT(Equals(a, d));
00075 }
00076
00077 void
00078 testTolerance()
00079 {
00080 Array2dScalarReal64* a = MakeFromValue<Array2dScalarReal64>(0.0, 4, 4, 0, 0);
00081 Array2dScalarReal64* b = MakeFromValue<Array2dScalarReal64>(0.1, 4, 4, 0, 0);
00082 Array2dScalarReal64* c = MakeFromValue<Array2dScalarReal64>(1.0, 4, 4, 0, 0);
00083 CPPUNIT_ASSERT(Equals(a, b, 0.1));
00084 CPPUNIT_ASSERT(!Equals(a, b, 0.09));
00085 CPPUNIT_ASSERT(Equals(a, c, 1.0));
00086 CPPUNIT_ASSERT(!Equals(a, c, 0.99));
00087 }
00088
00089
00090 private:
00091 ILOG_CLASS;
00092 };
00093
00094 ILOG_CLASS_INIT(TestEquals, Impala.Core.Array.Test);
00095 CPPUNIT_TEST_SUITE_REGISTRATION(TestEquals);
00096
00097 }
00098 }
00099 }
00100
00101 #endif