Skip to content

Commit

Permalink
Separated test code from BSTDictionary
Browse files Browse the repository at this point in the history
Signed-off-by: unknown <saq10002@iteb-219.ad.engr.uconn.edu>
  • Loading branch information
saq10002 committed Oct 11, 2014
1 parent 2f0577d commit d5dfb24
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 81 deletions.
1 change: 1 addition & 0 deletions YASI_12/YASI_12.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<ClInclude Include="ds.binarytree.test.h" />
<ClInclude Include="ds.binarytreebase.h" />
<ClInclude Include="ds.BSTDictionary.h" />
<ClInclude Include="ds.bstdictionary.test.h" />
<ClInclude Include="ds.comparable.h" />
<ClInclude Include="ds.dictionary.h" />
<ClInclude Include="ds.doublylinkedlist.h" />
Expand Down
61 changes: 35 additions & 26 deletions YASI_12/YASI_12.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
<Filter Include="Header Files\Data Structures\List">
<UniqueIdentifier>{dd3f1d18-aa29-4dd2-b39f-3fee286fb955}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Data Structures\Heap">
<UniqueIdentifier>{7c28c024-2e52-4642-b5b0-dd1332b5e474}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Data Structures\Graph">
<UniqueIdentifier>{9d029d58-d806-4503-8f54-cc27d0b9332d}</UniqueIdentifier>
</Filter>
Expand All @@ -40,6 +37,15 @@
<Filter Include="Header Files\Algorithms">
<UniqueIdentifier>{0f4869ec-8aa0-40e8-bf1a-dc5133ff0b1c}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Data Structures\Heap">
<UniqueIdentifier>{7c28c024-2e52-4642-b5b0-dd1332b5e474}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Data Structures\Hash Table">
<UniqueIdentifier>{fec8d7f4-c5ff-48ce-8c00-d8d7df79120a}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Data Structures\Priority Queue">
<UniqueIdentifier>{1be2ca50-f53a-4bb4-97ba-4043e8de9a85}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down Expand Up @@ -80,9 +86,6 @@
<ClInclude Include="ds.binaryheap.h">
<Filter>Header Files\Data Structures\Heap</Filter>
</ClInclude>
<ClInclude Include="ds.priorityqueue.h">
<Filter>Header Files\Data Structures\Heap</Filter>
</ClInclude>
<ClInclude Include="ds.list.h">
<Filter>Header Files\Data Structures\List</Filter>
</ClInclude>
Expand Down Expand Up @@ -119,21 +122,6 @@
<ClInclude Include="Sorter.h">
<Filter>Header Files\nonproject</Filter>
</ClInclude>
<ClInclude Include="ds.hashtablebase.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.LinearProbingHashTable.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.SeparateChainingHashTable.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.IntLinearProbingHashTable.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.HopScotchHashTable.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.graph.h">
<Filter>Header Files\Data Structures\Graph</Filter>
</ClInclude>
Expand Down Expand Up @@ -170,14 +158,35 @@
<ClInclude Include="ds.mutableheap.test.h">
<Filter>Header Files\Data Structures\Heap</Filter>
</ClInclude>
<ClInclude Include="ds.priorityqueue.test.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ds.mutablepriorityqueue.h">
<Filter>Header Files</Filter>
<Filter>Header Files\Data Structures\Priority Queue</Filter>
</ClInclude>
<ClInclude Include="ds.mutablepriorityqueue.test.h">
<Filter>Header Files</Filter>
<Filter>Header Files\Data Structures\Priority Queue</Filter>
</ClInclude>
<ClInclude Include="ds.priorityqueue.h">
<Filter>Header Files\Data Structures\Priority Queue</Filter>
</ClInclude>
<ClInclude Include="ds.priorityqueue.test.h">
<Filter>Header Files\Data Structures\Priority Queue</Filter>
</ClInclude>
<ClInclude Include="ds.hashtablebase.h">
<Filter>Header Files\Data Structures\Hash Table</Filter>
</ClInclude>
<ClInclude Include="ds.HopScotchHashTable.h">
<Filter>Header Files\Data Structures\Hash Table</Filter>
</ClInclude>
<ClInclude Include="ds.IntLinearProbingHashTable.h">
<Filter>Header Files\Data Structures\Hash Table</Filter>
</ClInclude>
<ClInclude Include="ds.LinearProbingHashTable.h">
<Filter>Header Files\Data Structures\Hash Table</Filter>
</ClInclude>
<ClInclude Include="ds.SeparateChainingHashTable.h">
<Filter>Header Files\Data Structures\Hash Table</Filter>
</ClInclude>
<ClInclude Include="ds.bstdictionary.test.h">
<Filter>Header Files\Data Structures\Dictionary</Filter>
</ClInclude>
</ItemGroup>
</Project>
57 changes: 5 additions & 52 deletions YASI_12/ds.BSTDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
#include "ds.binarysearchtree.h"
#include "ds.dictionary.h"
#include "utils.h"
#include "gtest\gtest.h"
#include <cstdlib>
#include "ds.aux.hastree.h"

// enable-disable testing classes in this file
#include "test.this.module.h"

using namespace std;

namespace yasi{
Expand All @@ -16,7 +19,7 @@ template <class Key, class Value = Key>
class BSTDictionary : public virtual IDictionary<Key, Value>,
public ds::aux::HasTree<BinarySearchTree< KVPair<Key, Value> > >{
/////////// enable testing ////////
friend class BSTDictionaryTest;
FRIEND_TEST_CLASS( BSTDictionaryTest );
typedef KVPair<Key, Value> Pair;
typedef BinarySearchTree<Pair> Tree;
protected:
Expand Down Expand Up @@ -64,57 +67,7 @@ class BSTDictionary : public virtual IDictionary<Key, Value>,

};

class BSTDictionaryTest : public yasi::Test{
typedef BSTDictionary<int> 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
Expand Down
62 changes: 62 additions & 0 deletions YASI_12/ds.bstdictionary.test.h
Original file line number Diff line number Diff line change
@@ -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<int> 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);
}
}
4 changes: 1 addition & 3 deletions YASI_12/main.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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){

Expand Down

0 comments on commit d5dfb24

Please sign in to comment.