From 39ba62d48fbcc549833175c4d421b66a27141b0e Mon Sep 17 00:00:00 2001 From: glx Date: Wed, 6 Sep 2006 13:58:31 +0000 Subject: (svn r6410) -remove unittest --- Makefile | 21 +- yapf/unittest/test_autocopyptr.h | 42 ---- yapf/unittest/test_binaryheap.h | 102 --------- yapf/unittest/test_blob.h | 61 ----- yapf/unittest/test_fixedsizearray.h | 113 ---------- yapf/unittest/test_hashtable.h | 72 ------ yapf/unittest/test_yapf.h | 359 ------------------------------ yapf/unittest/unittest.cpp | 159 ------------- yapf/unittest/unittest.h | 29 --- yapf/unittest/unittest.vcproj | 187 ---------------- yapf/unittest/unittest_vs80.vcproj | 432 ------------------------------------ 11 files changed, 2 insertions(+), 1575 deletions(-) delete mode 100644 yapf/unittest/test_autocopyptr.h delete mode 100644 yapf/unittest/test_binaryheap.h delete mode 100644 yapf/unittest/test_blob.h delete mode 100644 yapf/unittest/test_fixedsizearray.h delete mode 100644 yapf/unittest/test_hashtable.h delete mode 100644 yapf/unittest/test_yapf.h delete mode 100644 yapf/unittest/unittest.cpp delete mode 100644 yapf/unittest/unittest.h delete mode 100644 yapf/unittest/unittest.vcproj delete mode 100644 yapf/unittest/unittest_vs80.vcproj diff --git a/Makefile b/Makefile index 6649a8fe7..1a0d11f08 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,6 @@ # upgradeconf: add new options to old Makefile.config # osx: OS X application # release: used by OSX to make a dmg file ready to release -# unittest: compile and link ./yapf/unittest/unittest - test for some yapf related classes, and run it # Options: # @@ -253,7 +252,6 @@ TTD=openttd$(EXE) ENDIAN_CHECK=endian_check$(EXE) STRGEN=strgen/strgen$(EXE) OSXAPP="OpenTTD.app" -UNITTEST=unit_test$(EXE) ifdef RELEASE REV:=$(RELEASE) @@ -891,21 +889,6 @@ lang/%.lng: lang/%.txt $(STRGEN) lang/english.txt @echo '===> Compiling language $(*F)' $(Q)$(STRGEN) $(STRGEN_FLAGS) -s lang -d lang $< $(LANG_ERRORS) || rm -f $@ -# stupid KUDr doesn't know how to setup unittest dependencies (so rm,cp,rm) -# please don't blame him and repair it: -unittest: endian_host.h $(UPDATECONFIG) $(UNITTEST) rununittest -$(UNITTEST): yapf/unittest/unittest.cpp - @echo '===> Compiling and Linking $@' - $(Q)rm -f $(UNITTEST) - $(Q)$(CXX_HOST) $(CFLAGS_HOST) $(CDEFS) $< $(LIBS) $(LRT) -o $@ - -.PHONY: unittest - -rununittest: - @echo '===> Starting unittest' - $(Q)./$(UNITTEST) -.PHONY: rununittest - ifdef MORPHOS release: all @@ -960,7 +943,7 @@ FORCE: clean: @echo '===> Cleaning up' # endian.h is out-dated and no longer in use, so it can be removed soon - $(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX $(UNITTEST) + $(Q)rm -rf .deps *~ $(TTD) $(STRGEN) core table/strings.h $(LANGS) $(OBJS) $(OSX_MIDI_PLAYER_FILE) endian.h endian_host.h endian_target.h $(ENDIAN_CHECK) .OSX mrproper: clean $(Q)rm -rf $(MAKE_CONFIG) @@ -1043,7 +1026,7 @@ depend: @true # The include handles this automagically # Introduce the dependencies -ifeq ($(findstring $(MAKECMDGOALS), clean info mrproper upgradeconf unittest $(MAKE_CONFIG)),) +ifeq ($(findstring $(MAKECMDGOALS), clean info mrproper upgradeconf $(MAKE_CONFIG)),) -include $(DEPS) endif diff --git a/yapf/unittest/test_autocopyptr.h b/yapf/unittest/test_autocopyptr.h deleted file mode 100644 index 0e4d4dfef..000000000 --- a/yapf/unittest/test_autocopyptr.h +++ /dev/null @@ -1,42 +0,0 @@ -/* $Id$ */ - -struct CData -{ - int val; - - FORCEINLINE CData() : val(0) {NumInstances()++; /*DBG("DCata::ctor()\n");*/} - FORCEINLINE CData(const CData& src) : val(src.val) {NumInstances()++; /*DBG("DCata::ctor(%d)\n", val);*/} - FORCEINLINE ~CData() {NumInstances()--; /*DBG("DCata::dtor(%d)\n", val);*/} - - FORCEINLINE bool operator < (const CData& other) const {return (val < other.val);} - - FORCEINLINE static int& NumInstances() { static int num_instances = 0; return num_instances; }; - -}; - -typedef CAutoCopyPtrT PData; - -static int TestAutoCopyPtr(bool silent) -{ - int res = 0; - { - PData p1, p3; - p1->val = 4; - PData p2; p2 = p1; - p2->val = 6; - DBG("\n%d, %d", p1->val, p2->val); - CHECK_INT(0, p1->val, 4); - CHECK_INT(1, p2->val, 6); - - p2 = p1; - p3 = p1; - p2->val = 7; - DBG("\n%d, %d", p1->val, p2->val); - CHECK_INT(2, p3->val, 4); - CHECK_INT(3, p2->val, 7); - - CHECK_INT(4, CData::NumInstances(), 3); - } - CHECK_INT(5, CData::NumInstances(), 0); - return res; -} diff --git a/yapf/unittest/test_binaryheap.h b/yapf/unittest/test_binaryheap.h deleted file mode 100644 index 114f86985..000000000 --- a/yapf/unittest/test_binaryheap.h +++ /dev/null @@ -1,102 +0,0 @@ -/* $Id$ */ - -// this test uses CData structure defined in test_autocopyptr.h - -static int TestBinaryHeap1(bool silent) -{ - CData::NumInstances() = 0; - int res = 0; - { - const int max_items = 10000; - const int total_adds = 1000000; - CBinaryHeapT bh(max_items); - CFixedSizeArrayT data; - - - DBG("\nFilling BinaryHeap with %d items...", max_items); - CHECK_INT(0, bh.Size(), 0); - CHECK_INT(1, CData::NumInstances(), 0); - int i = 0; - for (; i < max_items; i++) { - CData& d = data.Add(); - d.val = rand() & 0xFFFF; - bh.Push(d); - } - CHECK_INT(2, bh.Size(), max_items); - CHECK_INT(3, CData::NumInstances(), max_items); - - - DBG("\nShaking items %d times...", total_adds); - int num_last = bh.GetHead().val; - for (i = 0; i < total_adds; i++) { - CData& d = bh.PopHead(); - //printf("\nd->val = %d, num_last = %d", d->val, num_last); - CHECK_INT(4, d.val < num_last, 0); - if(d.val < num_last) { - printf("Sort error @ item %d", i); - } - num_last = d.val; - d.val += rand() & 0xFFFF; - bh.Push(d); - } - - - DBG("\nDone!"); - CHECK_INT(5, bh.Size(), max_items); - CHECK_INT(6, CData::NumInstances(), max_items); - } - CHECK_INT(7, CData::NumInstances(), 0); - return res; -} - - - -// this test uses CData and PData structures defined in test_autocopyptr.h - -static int TestBinaryHeap2(bool silent) -{ - CData::NumInstances() = 0; - int res = 0; - { - const int max_items = 10000; - const int total_adds = 1000000; - CBinaryHeapT bh(max_items); - CFixedSizeArrayT data; - - - DBG("\nFilling BinaryHeap with %d items...", max_items); - CHECK_INT(0, bh.Size(), 0); - CHECK_INT(1, CData::NumInstances(), 0); - int i = 0; - for (; i < max_items; i++) { - CData& d = data.Add(); - d.val = rand() & 0xFFFF; - bh.Push(d); - } - CHECK_INT(2, bh.Size(), max_items); - CHECK_INT(3, CData::NumInstances(), max_items); - - - DBG("\nShaking items %d times...", total_adds); - int num_last = bh.GetHead().val; - for (i = 0; i < total_adds; i++) { - CData& d = bh.GetHead(); - bh.RemoveHead(); - //printf("\nd->val = %d, num_last = %d", d->val, num_last); - CHECK_INT(4, d.val < num_last, 0); - if(d.val < num_last) { - printf("Sort error @ item %d", i); - } - num_last = d.val; - d.val += rand() & 0xFFFF; - bh.Push(d); - } - - - DBG("\nDone!"); - CHECK_INT(5, bh.Size(), max_items); - CHECK_INT(6, CData::NumInstances(), max_items); - } - CHECK_INT(7, CData::NumInstances(), 0); - return res; -} diff --git a/yapf/unittest/test_blob.h b/yapf/unittest/test_blob.h deleted file mode 100644 index 5f266b0f7..000000000 --- a/yapf/unittest/test_blob.h +++ /dev/null @@ -1,61 +0,0 @@ -/* $Id$ */ - -static int TestBlob1(bool silent) -{ - typedef CBlobT Blob; - int res = 0; - { - Blob a; - Blob b; - CHECK_INT(0, a.IsEmpty(), true); - CHECK_INT(1, a.Size(), 0); - - const int nItems = 10; - - { - for (int i = 1; i <= nItems; i++) { - a.Append(i); - CHECK_INT(2, a.IsEmpty(), false); - CHECK_INT(3, a.Size(), i); - } - } - - { - for (int i = 1; i <= nItems; i++) { - CHECK_INT(4, *a.Data(i - 1), i); - } - } - } - return res; -} - -static int TestBlob2(bool silent) -{ - typedef CBlobT Blob; - int res = 0; - { - Blob a; - Blob b; - CHECK_INT(0, a.IsEmpty(), true); - CHECK_INT(1, a.Size(), 0); - - const int nItems = 10; - - { - for (int i = 1; i <= nItems; i++) { - a.Append(CFsaItem(i)); - CHECK_INT(2, a.IsEmpty(), false); - CHECK_INT(3, a.Size(), i); - } - } - { - for (int i = 1; i <= nItems; i++) { - CHECK_INT(4, a.Data(i - 1)->i, i); - } - } - CHECK_INT(15, CFsaItem::NumInstances(), nItems); - } - CHECK_INT(16, CFsaItem::NumInstances(), 0); - - return res; -} diff --git a/yapf/unittest/test_fixedsizearray.h b/yapf/unittest/test_fixedsizearray.h deleted file mode 100644 index 3a08dde7c..000000000 --- a/yapf/unittest/test_fixedsizearray.h +++ /dev/null @@ -1,113 +0,0 @@ -/* $Id$ */ - -struct CFsaItem -{ - int i; - - FORCEINLINE static int& NumInstances() { static int num_instances = 0; return num_instances; }; - - FORCEINLINE CFsaItem(int i = 0) - { - this->i = i; - NumInstances()++; - DBG("(*)"); - } - - FORCEINLINE CFsaItem(const CFsaItem& src) - { - this->i = src.i; - NumInstances()++; - DBG("(c)"); - } - - FORCEINLINE ~CFsaItem() - { - NumInstances()--; - DBG("(-)"); - } -}; - -typedef CFixedSizeArrayT CSubArray; -typedef CFixedSizeArrayT CSuperArray; - -static int TestFixedSizeArray(bool silent) -{ - int res = 0; - { - CSuperArray a; - - CHECK_INT(0, a.IsFull(), false); - CHECK_INT(1, a.IsEmpty(), true); - - CSubArray& b1 = a.Add(); - b1.Add().i = 1; - new(&b1.AddNC())CFsaItem(2); - - CSubArray& b2 = a.Add(); - new(&b2.AddNC())CFsaItem(3); - b2.Add().i = 4; - - CSubArray& b3 = a.AddNC(); - new(&b3)CSubArray(b1); - - CSubArray& b4 = a.AddNC(); - new(&b4)CSubArray(b2); - - CHECK_INT(2, a[0][0].i, 1); - CHECK_INT(3, b1[1].i, 2); - CHECK_INT(4, b1.Size(), 2); - CHECK_INT(5, a[3][0].i, 3); - CHECK_INT(6, a[3][1].i, 4); - CHECK_INT(7, CFsaItem::NumInstances(), 4); - CHECK_INT(8, a.IsFull(), true); - CHECK_INT(9, a.IsEmpty(), false); - CHECK_INT(10, a[3].IsFull(), false); - CHECK_INT(11, a[3].IsEmpty(), false); - } - CHECK_INT(12, CFsaItem::NumInstances(), 0); - - return res; -} - -typedef CArrayT CArray; - -static int TestArray(bool silent) -{ - int res = 0; - { - CArray a; - - CHECK_INT(0, a.IsFull(), false); - CHECK_INT(1, a.IsEmpty(), true); - - CHECK_INT(2, a.Size(), 0); - - a.Add().i = 1; - CHECK_INT(3, a.Size(), 1); - - new(&a.AddNC())CFsaItem(2); - CHECK_INT(4, a.Size(), 2); - - CHECK_INT(5, a.IsFull(), false); - CHECK_INT(6, a.IsEmpty(), false); - - a.Add().i = 3; - CHECK_INT(7, a.Size(), 3); - - new(&a.AddNC())CFsaItem(4); - CHECK_INT(8, a.Size(), 4); - - CHECK_INT(9, a[0].i, 1); - CHECK_INT(10, a[1].i, 2); - CHECK_INT(11, a[2].i, 3); - CHECK_INT(12, a[3].i, 4); - - CHECK_INT(13, a.IsFull(), true); - CHECK_INT(14, a.IsEmpty(), false); - - CHECK_INT(15, CFsaItem::NumInstances(), 4); - } - CHECK_INT(16, CFsaItem::NumInstances(), 0); - - return res; -} diff --git a/yapf/unittest/test_hashtable.h b/yapf/unittest/test_hashtable.h deleted file mode 100644 index 7b794b848..000000000 --- a/yapf/unittest/test_hashtable.h +++ /dev/null @@ -1,72 +0,0 @@ -/* $Id$ */ - -struct CHashItem1 { - struct CKey { - int k; - FORCEINLINE int CalcHash() const {return k;}; - FORCEINLINE bool operator == (const CKey& other) const {return (k == other.k);} - }; - typedef CKey Key; - CKey key; - int val; - CHashItem1* m_next; - - CHashItem1() : m_next(NULL) {} - FORCEINLINE const Key& GetKey() const {return key;} - CHashItem1* GetHashNext() {return m_next;} - void SetHashNext(CHashItem1* next) {m_next = next;} -}; - -static int TestHashTable1(bool silent) -{ - typedef CHashItem1 Item; - typedef CHashTableT HashTable1_t; - typedef CArrayT Array_t; - typedef CHashTableT HashTable2_t; - - int res = 0; - { - HashTable1_t ht1; - HashTable2_t ht2; - Array_t ar1; - Array_t ar2; - -#ifdef _DEBUG - static const int nItems = 10000; -#else - static const int nItems = 1000000; -#endif - { - srand(0); - for (int i = 0; i < nItems; i++) { - int r1 = i; - int r2 = rand() & 0x0000FFFF | (rand() << 16); - Item& I1 = ar1.Add(); - Item& I2 = ar2.Add(); - I1.key.k = r1; - I2.key.k = r1; - I1.val = r2; - I2.val = r2; - ht1.Push(I1); - ht2.Push(I2); - } - } - { - srand(0); - for (int i = 0; i < nItems; i++) { - int r1 = i; - int r2 = rand() & 0x0000FFFF | (rand() << 16); - HashTable1_t::Tkey k; k.k = r1; - Item& i1 = ht1.Find(k); - Item& i2 = ht2.Find(k); - - CHECK_INT(0, &i1 != NULL, 1); - CHECK_INT(1, &i2 != NULL, 1); - - if (&i1 != NULL) CHECK_INT(2, i1.val, r2); - if (&i2 != NULL) CHECK_INT(3, i2.val, r2); - } - } - } - return res; -} diff --git a/yapf/unittest/test_yapf.h b/yapf/unittest/test_yapf.h deleted file mode 100644 index 685e6fcf7..000000000 --- a/yapf/unittest/test_yapf.h +++ /dev/null @@ -1,359 +0,0 @@ -/* $Id$ */ - -#include "../yapf_base.hpp" - -struct CYapfMap1 -{ - enum {xMax = 32, yMax = 68}; - static int MapZ(int x, int y) - { - static const char *z1[yMax] = { - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000001000000000000000000000000000000000000000000000000000000A", - "A000000000001000000000000000000000000000000000000000000000000000000A", - "A000033333333333000000000000000000000000000000000000000000000000000A", - "A000030000000000000000000000000000000000000000000000000000000000000A", - "A000030000000000000000000000000000000000000000000000000000000000000A", - "A000030000000000000000000000000000000000000000000000000000000000000A", - "A000030000000000000000000000000000000000000000000000000000000000000A", - "A000030000000000000000000000000000000000000000000000000000000000000A", - "A210030000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A011333323333333233333333333333333333333333333333333333333333000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A210030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000230000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000000000000000000000000000003333333333333333333333333333333000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - }; - - static const char *z2[yMax] = { - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A003333333333333333333333333333333333333333333333333300000000000000A", - "A003000000001000000000000000000000000000000000000000300000000000000A", - "A003000000001000000000000000000000000000000000000000300000000000000A", - "A003333333333333333333333333333333333333300000000000300000000000000A", - "A000030000000000000000000000000000000000300000000000300000000000000A", - "A000030000000000000000000000000000000000333333333333300000000000000A", - "A000030000000000000000000000000000000000300000000000000000000000000A", - "A000030000000000000000000000000000000000300000000000000000000000000A", - "A000030000000000000000000000000000000000300000000000000000000000000A", - "A210030000000000000000000000000000000000300000000000000000000000000A", - "A000000000000000000000000000000000000000333300000000000000000000000A", - "A000000000000000000000000000000000000000000300000000000000000000000A", - "A000000000000000000000000000000000000000000300000000000000000000000A", - "A000000000000000000000000000000000000000000300000000000000000000000A", - "A012333323333333233333333333333333333333333333333333333333333000000A", - "A000030000000000000000000000000000000000000000000000000000003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A210030000000000000000000000000000000000000000000000000330003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000230000000000000000000000000000000000000000000000000300003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000030000000000000000000000000000000000000000000000000300003000000A", - "A000000000000000000000000000003333333333333333333333333333333000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "A000000000000000000000000000000000000000000000000000000000000000000A", - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - }; - - static const char **z = z1; - - if (x >= 0 && x < xMax && y >= 0 && y < yMax) { - int ret = z[x][y]; - return ret; - } - return z[0][0]; - } -}; - -struct CNodeKey1 { - int m_x; - int m_y; - Trackdir m_td; - DiagDirection m_exitdir; - - CNodeKey1() : m_x(0), m_y(0), m_td(INVALID_TRACKDIR) {} - - int CalcHash() const {return m_x | (m_y << 5) | (m_td << 10);} - bool operator == (const CNodeKey1& other) const {return (m_x == other.m_x) && (m_y == other.m_y) && (m_td == other.m_td);} -}; - -struct CNodeKey2 : public CNodeKey1 -{ - int CalcHash() const {return m_x | (m_y << 5) | (m_exitdir << 10);} - bool operator == (const CNodeKey1& other) const {return (m_x == other.m_x) && (m_y == other.m_y) && (m_exitdir == other.m_exitdir);} -}; - -template -struct CTestYapfNodeT { - typedef Tkey_ Key; - typedef CTestYapfNodeT Node; - - Tkey_ m_key; - CTestYapfNodeT *m_parent; - int m_cost; - int m_estimate; - CTestYapfNodeT *m_next; - - CTestYapfNodeT(CTestYapfNodeT* parent = NULL) : m_parent(parent), m_cost(0), m_estimate(0), m_next(NULL) {} - - const Tkey_& GetKey() const {return m_key;} - int GetCost() {return m_cost;} - int GetCostEstimate() {return m_estimate;} - bool operator < (const CTestYapfNodeT& other) const {return m_estimate < other.m_estimate;} - CTestYapfNodeT* GetHashNext() {return m_next;} - void SetHashNext(CTestYapfNodeT* next) {m_next = next;} -}; - -typedef CTestYapfNodeT CYapfNode1; -typedef CTestYapfNodeT CYapfNode2; - -template -struct CYapfTestBaseT -{ - typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class) - typedef typename Types::NodeList::Titem Node; ///< this will be our node type - typedef typename Node::Key Key; ///< key to hash tables - typedef typename Types::Map Map; - - int m_x1, m_y1; - int m_x2, m_y2; - Trackdir m_td1; - - CYapfTestBaseT() - : m_x1(0), m_y1(0), m_x2(0), m_y2(0), m_td1(INVALID_TRACKDIR) - { - } - - void Set(int x1, int y1, int x2, int y2, Trackdir td1) - { - m_x1 = x1; - m_y1 = y1; - m_x2 = x2; - m_y2 = y2; - m_td1 = td1; - } - - /// to access inherited path finder - Tpf& Yapf() {return *static_cast(this);} - FORCEINLINE char TransportTypeChar() const {return 'T';} - - /** Called by YAPF to move from the given node to the next tile. For each - * reachable trackdir on the new tile creates new node, initializes it - * and adds it to the open list by calling Yapf().AddNewNode(n) */ - FORCEINLINE void PfFollowNode(Node& org) - { - int x_org = org.m_key.m_x; - int y_org = org.m_key.m_y; - int z_org = Map::MapZ(x_org, y_org); - DiagDirection exitdir = TrackdirToExitdir(org.m_key.m_td); - - TileIndexDiffC diff = TileIndexDiffCByDiagDir(exitdir); - int x_new = x_org + diff.x; - int y_new = y_org + diff.y; - int z_new = Map::MapZ(x_new, y_new); - - int z_diff = z_new - z_org; - if (abs(z_diff) > 1) return; - - TrackdirBits trackdirs = DiagdirReachesTrackdirs(exitdir); - TrackdirBits trackdirs90 = TrackdirCrossesTrackdirs(org.m_key.m_td); - trackdirs &= (TrackdirBits)~(int)trackdirs90; - - while (trackdirs != TRACKDIR_BIT_NONE) { - Trackdir td_new = (Trackdir)FindFirstBit2x64(trackdirs); - trackdirs = (TrackdirBits)KillFirstBit2x64(trackdirs); - - Node& n = Yapf().CreateNewNode(); - n.m_key.m_x = x_new; - n.m_key.m_y = y_new; - n.m_key.m_td = td_new; - n.m_key.m_exitdir = TrackdirToExitdir(n.m_key.m_td); - n.m_parent = &org; - Yapf().AddNewNode(n); - } - } - - /// Called when YAPF needs to place origin nodes into open list - FORCEINLINE void PfSetStartupNodes() - { - Node& n1 = Yapf().CreateNewNode(); - n1.m_key.m_x = m_x1; - n1.m_key.m_y = m_y1; - n1.m_key.m_td = m_td1; - n1.m_key.m_exitdir = TrackdirToExitdir(n1.m_key.m_td); - Yapf().AddStartupNode(n1); - } - - /** Called by YAPF to calculate the cost from the origin to the given node. - * Calculates only the cost of given node, adds it to the parent node cost - * and stores the result into Node::m_cost member */ - FORCEINLINE bool PfCalcCost(Node& n) - { - // base tile cost depending on distance - int c = IsDiagonalTrackdir(n.m_key.m_td) ? 10 : 7; - // additional penalty for curve - if (n.m_parent != NULL && n.m_key.m_td != n.m_parent->m_key.m_td) c += 3; - // z-difference cost - int z_new = Map::MapZ(n.m_key.m_x, n.m_key.m_y); - int z_old = Map::MapZ(n.m_parent->m_key.m_x, n.m_parent->m_key.m_y); - if (z_new > z_old) n.m_cost += (z_new - z_old) * 10; - // apply it - n.m_cost = n.m_parent->m_cost + c; - return true; - } - - /** Called by YAPF to calculate cost estimate. Calculates distance to the destination - * adds it to the actual cost from origin and stores the sum to the Node::m_estimate */ - FORCEINLINE bool PfCalcEstimate(Node& n) - { - int dx = abs(n.m_key.m_x - m_x2); - int dy = abs(n.m_key.m_y - m_y2); - int dd = min(dx, dy); - int dxy = abs(dx - dy); - int d = 14 * dd + 10 * dxy; - n.m_estimate = n.m_cost + d /*+ d / 4*/; - return true; - } - - /// Called by YAPF to detect if node ends in the desired destination - FORCEINLINE bool PfDetectDestination(Node& n) - { - bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2); - return bDest; - } - - static int stTestAstar(bool silent) - { - Tpf pf; - pf.Set(3, 3, 20, 56, TRACKDIR_X_NE); - int ret = pf.TestAstar(silent); - return ret; - } - - int TestAstar(bool silent) - { - CPerformanceTimer pc; - - pc.Start(); - bool bRet = Yapf().FindPath(NULL); - pc.Stop(); - - if (!bRet) return 1; - - typedef CFixedSizeArrayT Row; - typedef CFixedSizeArrayT Box; - - Box box; - { - for (int x = 0; x < Map::xMax; x++) { - Row& row = box.Add(); - for (int y = 0; y < Map::yMax; y++) { - row.Add() = Map::MapZ(x, y); - } - } - } - int nPathTiles = 0; - { - for (Node* pNode = &Yapf().GetBestNode(); pNode != NULL; pNode = pNode->m_parent) { - box[pNode->m_key.m_x][pNode->m_key.m_y] = '.'; - nPathTiles++; - } - } - { - printf("\n\n"); - for (int x = 0; x < Map::xMax; x++) { - for (int y = 0; y < Map::yMax; y++) { - printf("%c", box[x][y]); - } - printf("\n"); - } - } - - { - printf("\n"); - printf("Path Tiles: %6d\n", nPathTiles); -// printf("Closed nodes: %6d\n", pf.m_nodes.ClosedCount()); -// printf("Open nodes: %6d\n", pf.m_nodes.OpenCount()); -// printf("A-star rounds: %6d\n", pf.m_num_steps); - } - int total_time = pc.Get(1000000); - if (total_time != 0) - printf("Total time: %6d us\n", pc.Get(1000000)); - - printf("\n"); - - { - int nCnt = Yapf().m_nodes.TotalCount(); - for (int i = 0; i < nCnt; i++) { - Node& n = Yapf().m_nodes.ItemAt(i); - int& z = box[n.m_key.m_x][n.m_key.m_y]; - z = (z < 'a') ? 'a' : (z + 1); - } - } - { - for (int x = 0; x < Map::xMax; x++) { - for (int y = 0; y < Map::yMax; y++) { - printf("%c", box[x][y]); - } - printf("\n"); - } - } - - return 0; - } -}; - -struct CDummy1 {}; -struct CDummy2 {}; -struct CDummy3 {}; - -template -struct CYapf_TypesT -{ - typedef CYapf_TypesT Types; - - typedef Tpf_ Tpf; - typedef Tnode_list NodeList; - typedef Tmap Map; - typedef CYapfBaseT PfBase; - typedef CYapfTestBaseT PfFollow; - typedef CDummy1 PfOrigin; - typedef CDummy2 PfDestination; - typedef CYapfSegmentCostCacheNoneT PfCache; - typedef CDummy3 PfCost; -}; - -typedef CNodeList_HashTableT CNodeList1; -typedef CNodeList_HashTableT CNodeList2; - -struct CTestYapf1 - : public CYapfT > -{ -}; - -struct CTestYapf2 - : public CYapfT > -{ -}; diff --git a/yapf/unittest/unittest.cpp b/yapf/unittest/unittest.cpp deleted file mode 100644 index 33d3f3065..000000000 --- a/yapf/unittest/unittest.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* $Id$ */ - -#define UNITTEST - -#include "../../stdafx.h" - -EXTERN_C_BEGIN -#include "../../macros.h" -#include "../../tile.h" -#include "../../openttd.h" -#include "../../map.h" -#include "../../rail.h" -EXTERN_C_END - -//#include "../track_dir.hpp" - -#include "../yapf.hpp" - -#include "../autocopyptr.hpp" - -#include "unittest.h" - -#include "test_autocopyptr.h" -#include "test_binaryheap.h" -#include "test_fixedsizearray.h" -#include "test_blob.h" -#include "test_hashtable.h" -#include "test_yapf.h" - -int _total_pf_time_us = 0; - -int num_tests_failed = 0; -int num_tests_total = 0; -bool _dbg = false; - -int do_test(const char* name, TESTPROC test_proc, bool silent) -{ - printf("%s ", name); - if (!silent) {printf("[enter]:"); getc(stdin);} - _dbg = !silent; - fflush(stdout); - int res = test_proc(silent); - if (res == 0) - { - printf("%s OK\n", silent ? "..." : "\n"); - } - else { - printf("\n ERROR! (0x%X)\n", res); - printf("\nFailed cases:"); - int num_failed = 0; - for(int i = 0; i < 32; i++) { - if (((1 << i) & res) != 0) { - printf(" %d", i); - num_failed++; - } - } - printf("\n\nTotal: %d cases failed\n\n", num_failed); - } - - num_tests_total++; - if (res != 0) num_tests_failed++; - - return (res == 0) ? 0 : 1; -} - -struct TEST_RECORD { - const char* name; - TESTPROC testproc; -}; - -TEST_RECORD tests[] = { - {"AutoCopyPtr test" , &TestAutoCopyPtr }, - {"BinaryHeap test 1" , &TestBinaryHeap1 }, - {"BinaryHeap test 2" , &TestBinaryHeap2 }, - {"FixedSizeArray test", &TestFixedSizeArray }, - {"Array test" , &TestArray }, - {"Blob test 1" , &TestBlob1 }, - {"Blob test 2" , &TestBlob2 }, - {"HashTable test 1" , &TestHashTable1 }, - {"Yapf test 1" , &CTestYapf1::stTestAstar }, - {"Yapf test 2" , &CTestYapf2::stTestAstar }, - - {NULL , NULL }, -}; - -int main(int argc, char** argv) -{ - bool silent = (argc == 1); - - for (TEST_RECORD* tr = tests; tr->name != NULL; tr++) - do_test(tr->name, tr->testproc, silent); - - if (num_tests_failed == 0) - printf("\nALL %d TESTS PASSED OK!\n\n", num_tests_total); - else - printf("\n****** %d (from %d of total) TEST(S) FAILED! ******\n", num_tests_failed, num_tests_total); - return 0; -} - - - -extern "C" -const TileIndexDiffC _tileoffs_by_dir[] = { - {-1, 0}, - { 0, 1}, - { 1, 0}, - { 0, -1} -}; - -extern "C" -const byte _ffb_64[128] = { - 0, 0, 1, 0, 2, 0, 1, 0, - 3, 0, 1, 0, 2, 0, 1, 0, - 4, 0, 1, 0, 2, 0, 1, 0, - 3, 0, 1, 0, 2, 0, 1, 0, - 5, 0, 1, 0, 2, 0, 1, 0, - 3, 0, 1, 0, 2, 0, 1, 0, - 4, 0, 1, 0, 2, 0, 1, 0, - 3, 0, 1, 0, 2, 0, 1, 0, - - 0, 0, 0, 2, 0, 4, 4, 6, - 0, 8, 8, 10, 8, 12, 12, 14, - 0, 16, 16, 18, 16, 20, 20, 22, - 16, 24, 24, 26, 24, 28, 28, 30, - 0, 32, 32, 34, 32, 36, 36, 38, - 32, 40, 40, 42, 40, 44, 44, 46, - 32, 48, 48, 50, 48, 52, 52, 54, - 48, 56, 56, 58, 56, 60, 60, 62, -}; - -/* Maps a trackdir to the (4-way) direction the tile is exited when following -* that trackdir */ -extern "C" -const DiagDirection _trackdir_to_exitdir[] = { - DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE, - DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE, -}; - -/* Maps a diagonal direction to the all trackdirs that are connected to any -* track entering in this direction (including those making 90 degree turns) -*/ -extern "C" -const TrackdirBits _exitdir_reaches_trackdirs[] = { - TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */ - TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ - TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ - TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ -}; - -/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ -extern "C" -const TrackdirBits _track_crosses_trackdirs[] = { - TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ - TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ - TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ - TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ - TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ - TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E /* TRACK_RIGHT */ -}; diff --git a/yapf/unittest/unittest.h b/yapf/unittest/unittest.h deleted file mode 100644 index f448ea341..000000000 --- a/yapf/unittest/unittest.h +++ /dev/null @@ -1,29 +0,0 @@ -/* $Id$ */ - -#define UNITTEST - -extern int num_tests_failed; -extern int num_tests_total; - -extern bool _dbg; -#define DBG if(_dbg) printf - - -#define CHECK_INT(case_num, val, should_be) \ -{ \ - if((val) != (should_be)) { \ - res |= (1 << case_num); \ - printf("\n****** ERROR in case %d: " #val " = %d (should be %d)!", case_num, (val), (should_be)); \ - } \ -} - -typedef int(*TESTPROC)(bool silent); - -//#undef FORCEINLINE -//#define FORCEINLINE - - -#if defined(_WIN32) || defined(_WIN64) -# include -#else -#endif diff --git a/yapf/unittest/unittest.vcproj b/yapf/unittest/unittest.vcproj deleted file mode 100644 index 59d375bc5..000000000 --- a/yapf/unittest/unittest.vcproj +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/yapf/unittest/unittest_vs80.vcproj b/yapf/unittest/unittest_vs80.vcproj deleted file mode 100644 index cbf1815ed..000000000 --- a/yapf/unittest/unittest_vs80.vcproj +++ /dev/null @@ -1,432 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2