Skip to content

Commit

Permalink
Updated broken tests for inference extension
Browse files Browse the repository at this point in the history
  • Loading branch information
cwacek committed Sep 6, 2013
1 parent 6788d1d commit 8b02274
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion c_extensions/inferrer/structures.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "structures.h"

RQueue::RQueue(redisContext *c, string key,bool am_listener)
RQueue::RQueue(redisContext *c, string key, bool am_listener)
{
this->key = key;
this->c = c;
Expand Down
4 changes: 2 additions & 2 deletions c_extensions/inferrer/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CC = g++
GTESTDIR = gtest
TESTS = $(wildcard test_*.cc)
OBJECTS = $(patsubst %.cc, %.o, $(wildcard *.cc))
CFLAGS = -I$(GTESTDIR)/include -std=c++0x
LIBS = $(GTESTDIR)/libgtest.a ../../hiredis/libhiredis.a -lpthread
CFLAGS = -I$(GTESTDIR)/include -std=c++0x -g
LIBS = $(GTESTDIR)/build/libgtest_main.a $(GTESTDIR)/build/libgtest.a -lhiredis -lpthread

%.o: %.cc $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
Expand Down
62 changes: 31 additions & 31 deletions c_extensions/inferrer/test/test_pathset.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <gtest/gtest.h>
#include "../structures.h"

class PathSetTest : public ::testing::Test
class PathSetTest : public ::testing::Test
{
protected:
virtual void SetUp() {
p1_ = new Path("['1', '2', '3', '4']");
p2_ = new Path("['5', '6', '7', '8']");
p1_ = Path_ptr(new Path("['1', '2', '3', '4']"));
p2_ = Path_ptr(new Path("['5', '6', '7', '8']"));
origin = ASN_encode("1234");
ps_.add(origin,p1_);
}
Expand All @@ -17,8 +17,8 @@ class PathSetTest : public ::testing::Test
ps_.clear(origin2);
}

Path *p1_;
Path *p2_;
Path_ptr p1_;
Path_ptr p2_;
PathSet ps_;
asn_t origin;

Expand All @@ -38,7 +38,7 @@ TEST_F(PathSetTest, AddInsertsNewPath)

TEST_F(PathSetTest, DifferentPtrsCompareEqualIfPathsEqual)
{
Path *p1dup = new Path(*p1_);
Path_ptr p1dup = Path_ptr(new Path(*p1_));
PathPtrCmp cmp;

EXPECT_NE(p1dup,p1_);
Expand All @@ -57,7 +57,7 @@ TEST_F(PathSetTest, ComparatorCorrectlyOrders)
p1_->prepend("99",true);
ASSERT_FALSE(cmp(p1_,p2_))
<< p2_->cstr(true) << " should come before " << p1_->cstr(true);
ASSERT_TRUE(cmp(p2_,p1_));
ASSERT_TRUE(cmp(p2_,p1_));
p2_->prepend("20",false);
ASSERT_TRUE(cmp(p1_,p2_))
<< p1_->cstr(true) << " should come before " << p2_->cstr(true);
Expand All @@ -67,35 +67,35 @@ TEST_F(PathSetTest, ComparatorCorrectlyOrders)

TEST_F(PathSetTest, PeekNoCopyReturnsSameObject)
{
Path *p = ps_.peek(origin, false);
ASSERT_EQ(p1_, p)
Path_ptr p = ps_.peek(origin, false);
ASSERT_EQ(p1_, p)
<< "Inserted object pointer not equal to return value of peek()";
}

TEST_F(PathSetTest, PeekCopyCreatesNew)
{
Path *p = ps_.peek(origin, true);
ASSERT_NE(p1_, p)
Path_ptr p = ps_.peek(origin, true);
ASSERT_NE(p1_, p)
<< "Inserted object pointer equal to return value of peek()";
}

TEST_F(PathSetTest, ClearRemovesElementsForOrigin)
{
ASSERT_EQ(1,ps_.size(origin));
ASSERT_EQ(1, ps_.size(origin));
ps_.clear(origin);
ASSERT_EQ(0,ps_.size(origin));
Path *p = ps_.peek(origin,false);
ASSERT_EQ(0,p);
ASSERT_EQ(0, ps_.size(origin));
Path_ptr p = ps_.peek(origin, false);
ASSERT_FALSE(p);
}

TEST_F(PathSetTest, AddIdenticalIncrFrequency)
TEST_F(PathSetTest, AddIdenticalIncrFrequency)
{
ps_.add(origin,p1_);
Path *ret = ps_.peek(origin,false);
ASSERT_EQ(2, ret->frequency)
Path_ptr ret = ps_.peek(origin,false);
ASSERT_EQ(2, ret->frequency)
<< "Adding duplicate "<< ret->cstr() << " should increment frequency";

Path *p1dup = new Path(*p1_);
Path_ptr p1dup = Path_ptr(new Path(*p1_));
ps_.add(origin,p1dup);
ret = ps_.peek(origin,false);
ASSERT_EQ(3, ret->frequency)
Expand All @@ -105,34 +105,34 @@ TEST_F(PathSetTest, AddIdenticalIncrFrequency)

TEST_F(PathSetTest, PeekReturnsBestPath)
{
Path *ret = ps_.peek(origin,false);
Path_ptr ret = ps_.peek(origin,false);
ASSERT_EQ(ret, p1_);
asn_t origin2 = ASN_encode("5678");
ASSERT_EQ(0, ps_.size(origin2));

Path *p4 = new Path(*p1_);
Path_ptr p4 = Path_ptr(new Path(*p1_));
p4->prepend("99",false);

ps_.add(origin2,p4);
ret = ps_.peek(origin2,false);
ASSERT_EQ(p4, ret)
<< "[" << p4 << "] " << p4->cstr(false)
<< " should be better than "
ASSERT_EQ(p4, ret)
<< "[" << p4 << "] " << p4->cstr(false)
<< " should be better than "
<< "[" << ret << "] " << ret->cstr(false);

ps_.add(origin2,p2_);
ret = ps_.peek(origin2,false);
ASSERT_EQ(p2_, ret)
<< "[" << p2_ << "] " << p2_->cstr(false)
<< " should be better than "
ASSERT_EQ(p2_, ret)
<< "[" << p2_ << "] " << p2_->cstr(false)
<< " should be better than "
<< "[" << ret << "] " << ret->cstr(false);

Path *p3 = new Path("1 2 3");
Path_ptr p3 = Path_ptr(new Path("1 2 3"));
ps_.add(origin2,p3);
ret = ps_.peek(origin2,false);
ASSERT_EQ(p3, ret)
<< "[" << p3 << "] " << p3->cstr(false)
<< " should be better than "
ASSERT_EQ(p3, ret)
<< "[" << p3 << "] " << p3->cstr(false)
<< " should be better than "
<< "[" << ret << "] " << ret->cstr(false);

ps_.clear(origin2);
Expand Down
7 changes: 4 additions & 3 deletions c_extensions/inferrer/test/test_rqueue.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <stdio.h>
#include "../structures.h"
#include "../infer.h"

Expand Down Expand Up @@ -82,18 +83,18 @@ TEST_F(RQueueTest, DeleteRemovesListenerKey)
{
ASSERT_REDIS(c_);

RQueue *rq = new RQueue(c_,"sladfkjew",false);
RQueue *rq = new RQueue(c_, "sladfkjew", true);
char buf[64];
strncpy(buf,rq->listener_key,64);
r = rCommand(c_,"GET %s",buf);
int res = atoi(r->str);
ASSERT_EQ(1,res);
ASSERT_EQ(1, res);
freeReplyObject(r);

delete rq;
r = rCommand(c_,"GET %s", buf);
res = atoi(r->str);
ASSERT_EQ(1,res);
ASSERT_EQ(0,res);
freeReplyObject(r);
}

Expand Down

0 comments on commit 8b02274

Please sign in to comment.