diff --git a/YASI_12/YASI_12.vcxproj b/YASI_12/YASI_12.vcxproj index a47d2e8..aa309cc 100644 --- a/YASI_12/YASI_12.vcxproj +++ b/YASI_12/YASI_12.vcxproj @@ -85,6 +85,7 @@ + diff --git a/YASI_12/YASI_12.vcxproj.filters b/YASI_12/YASI_12.vcxproj.filters index 4fa2405..c8be0f4 100644 --- a/YASI_12/YASI_12.vcxproj.filters +++ b/YASI_12/YASI_12.vcxproj.filters @@ -28,9 +28,6 @@ {dd3f1d18-aa29-4dd2-b39f-3fee286fb955} - - {7c28c024-2e52-4642-b5b0-dd1332b5e474} - {9d029d58-d806-4503-8f54-cc27d0b9332d} @@ -40,6 +37,15 @@ {0f4869ec-8aa0-40e8-bf1a-dc5133ff0b1c} + + {7c28c024-2e52-4642-b5b0-dd1332b5e474} + + + {fec8d7f4-c5ff-48ce-8c00-d8d7df79120a} + + + {1be2ca50-f53a-4bb4-97ba-4043e8de9a85} + @@ -80,9 +86,6 @@ Header Files\Data Structures\Heap - - Header Files\Data Structures\Heap - Header Files\Data Structures\List @@ -119,21 +122,6 @@ Header Files\nonproject - - Header Files\Data Structures\Dictionary - - - Header Files\Data Structures\Dictionary - - - Header Files\Data Structures\Dictionary - - - Header Files\Data Structures\Dictionary - - - Header Files\Data Structures\Dictionary - Header Files\Data Structures\Graph @@ -170,14 +158,35 @@ Header Files\Data Structures\Heap - - Header Files - - Header Files + Header Files\Data Structures\Priority Queue - Header Files + Header Files\Data Structures\Priority Queue + + + Header Files\Data Structures\Priority Queue + + + Header Files\Data Structures\Priority Queue + + + Header Files\Data Structures\Hash Table + + + Header Files\Data Structures\Hash Table + + + Header Files\Data Structures\Hash Table + + + Header Files\Data Structures\Hash Table + + + Header Files\Data Structures\Hash Table + + + Header Files\Data Structures\Dictionary \ No newline at end of file diff --git a/YASI_12/ds.BSTDictionary.h b/YASI_12/ds.BSTDictionary.h index 707bc39..a9991d0 100644 --- a/YASI_12/ds.BSTDictionary.h +++ b/YASI_12/ds.BSTDictionary.h @@ -3,9 +3,12 @@ #include "ds.binarysearchtree.h" #include "ds.dictionary.h" #include "utils.h" -#include "gtest\gtest.h" #include #include "ds.aux.hastree.h" + +// enable-disable testing classes in this file +#include "test.this.module.h" + using namespace std; namespace yasi{ @@ -16,7 +19,7 @@ template class BSTDictionary : public virtual IDictionary, public ds::aux::HasTree > >{ /////////// enable testing //////// - friend class BSTDictionaryTest; + FRIEND_TEST_CLASS( BSTDictionaryTest ); typedef KVPair Pair; typedef BinarySearchTree Tree; protected: @@ -64,57 +67,7 @@ class BSTDictionary : public virtual IDictionary, }; -class BSTDictionaryTest : public yasi::Test{ - typedef BSTDictionary Dict; -public: - void all(){ - Dict d; - ASSERT_EQ(0, d.size()) << "size not 0"; - ASSERT_EQ(true, d.empty()) << "d not empty"; - - for (int i = 0; i < 20; i += 5){ - // keys: 0, 5, 10, 15 - // values: 0, 50, 100, 150 - d.insert(i, i * 10); - } - ASSERT_EQ(4, d.size()) << "size not 4"; - ASSERT_EQ(false, d.empty()) << "d empty"; - - // insert an already-existing item; should update current value - d.insert(5, 500); - ASSERT_EQ(4, d.size()) << "size changed by re-insertion"; - ASSERT_EQ(500, *d.find(5)) << "value not updated by re-insertion"; - - /// try to find non-existent items - ASSERT_EQ(0, (int)d.find(3)) << "non-null ptr for non-existent key"; - // try to find existent items - ASSERT_EQ(500, * d.find(5)) << "value at 5 not 500"; - ASSERT_EQ(150, * d.find(15)) << "value at 15 not 150"; - - // remove some items - d.remove(5); - d.remove(15); - ASSERT_EQ(2, d.size()) << "size not 2"; - - /// try to find non-existent items - ASSERT_EQ(0, (int)d.find(3)) << "non-null ptr for non-existent key 3"; - ASSERT_EQ(0, (int)d.find(5)) << "non-null ptr for non-existent key 5"; - ASSERT_EQ(0, (int)d.find(15)) << "non-null ptr for non-existent key 15"; - // try to find existent items - ASSERT_EQ(0, *d.find(0)) << "value at 0 not 50"; - ASSERT_EQ(100, *d.find(10)) << "value at 10 not 100"; - - // clear - d.clear(); - ASSERT_EQ(0, d.size()) << "size not 0"; - ASSERT_EQ(true, d.empty()) << "d not empty"; - - - } - -}; -ADD_TEST_F(BSTDictionaryTest, all); }// namespace ds diff --git a/YASI_12/ds.bstdictionary.test.h b/YASI_12/ds.bstdictionary.test.h new file mode 100644 index 0000000..ecfee65 --- /dev/null +++ b/YASI_12/ds.bstdictionary.test.h @@ -0,0 +1,62 @@ +#pragma once + +#if YASI_TEST_THIS_MODULE != 1 +#define YASI_TEST_THIS_MODULE 1 +#endif +#include "ds.BSTdictionary.h" + +namespace yasi{ + namespace ds{ + class BSTDictionaryTest : public yasi::Test{ + typedef BSTDictionary Dict; + public: + void all(){ + Dict d; + ASSERT_EQ(0, d.size()) << "size not 0"; + ASSERT_EQ(true, d.empty()) << "d not empty"; + + for (int i = 0; i < 20; i += 5){ + // keys: 0, 5, 10, 15 + // values: 0, 50, 100, 150 + d.insert(i, i * 10); + } + ASSERT_EQ(4, d.size()) << "size not 4"; + ASSERT_EQ(false, d.empty()) << "d empty"; + + // insert an already-existing item; should update current value + d.insert(5, 500); + ASSERT_EQ(4, d.size()) << "size changed by re-insertion"; + ASSERT_EQ(500, *d.find(5)) << "value not updated by re-insertion"; + + /// try to find non-existent items + ASSERT_EQ(0, (int)d.find(3)) << "non-null ptr for non-existent key"; + // try to find existent items + ASSERT_EQ(500, *d.find(5)) << "value at 5 not 500"; + ASSERT_EQ(150, *d.find(15)) << "value at 15 not 150"; + + // remove some items + d.remove(5); + d.remove(15); + ASSERT_EQ(2, d.size()) << "size not 2"; + + /// try to find non-existent items + ASSERT_EQ(0, (int)d.find(3)) << "non-null ptr for non-existent key 3"; + ASSERT_EQ(0, (int)d.find(5)) << "non-null ptr for non-existent key 5"; + ASSERT_EQ(0, (int)d.find(15)) << "non-null ptr for non-existent key 15"; + // try to find existent items + ASSERT_EQ(0, *d.find(0)) << "value at 0 not 50"; + ASSERT_EQ(100, *d.find(10)) << "value at 10 not 100"; + + // clear + d.clear(); + ASSERT_EQ(0, d.size()) << "size not 0"; + ASSERT_EQ(true, d.empty()) << "d not empty"; + + + } + + }; + + ADD_TEST_F(BSTDictionaryTest, all); + } +} \ No newline at end of file diff --git a/YASI_12/main.cpp b/YASI_12/main.cpp index cb3186a..e3628ed 100644 --- a/YASI_12/main.cpp +++ b/YASI_12/main.cpp @@ -1,8 +1,5 @@ #include "common.h" -//#include "ds.binaryheap.h" -//#include "ds.binarysearchtree.h" -//#include "ds.priorityqueue.h" //#include "ds.BSTDictionary.h" //#include "ds.separatechaininghashtable.h" //#include "ds.intlinearprobinghashtable.h" @@ -33,6 +30,7 @@ using namespace std; #include "ds.mutableheap.test.h" #include "ds.priorityqueue.test.h" #include "ds.mutablepriorityqueue.test.h" +#include "ds.bstdictionary.test.h" int testAll(int* argc, char** argv){