Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Up Tests #16

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
mkdir -p $(BUILDDIR)
echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $<

test: test/*
@echo "Testing..."
g++ -std=c++11 -o bin/test -I include -I src test/*.cpp

clean:
@echo "Cleaning..."
@echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
3,461 changes: 3,461 additions & 0 deletions include/doctest.h

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions include/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ class Word {
// Get the string value of the Word
std::string getVal();

// Set the string value of the Word
void setVal(std::string newWord);

// If a leader, get the number of times the word leads its base word
// If a base word, get the number of times it appears in the model
int getFrequency();

// Set the Word's frequency
void setFrequency(int newFrequency);

// Increment the frequency count by 1
void incrementFrequency();

Expand Down
10 changes: 1 addition & 9 deletions src/word.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Word::Word() {
value = "";
frequency = 0;
stressPattern = {};
stressPattern = "";
}

Word::Word(std::string val, std::string stress) {
Expand Down Expand Up @@ -41,14 +41,6 @@ std::string Word::getStressPattern() {
return stressPattern;
}

void Word::setVal(std::string newValue) {
value = newValue;
}

void Word::setFrequency(int newFrequency) {
frequency = newFrequency;
}

void Word::incrementFrequency() {
frequency++;
}
Expand Down
3 changes: 3 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

#include "doctest.h"
35 changes: 35 additions & 0 deletions test/utils_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "doctest.h"

#include "utils.cpp"

TEST_CASE("capitalizes a string") {
CHECK(Utils::allCaps("test") == "TEST");
CHECK(Utils::allCaps("TEST") == "TEST");
CHECK(Utils::allCaps("under_score") == "UNDER_SCORE");
CHECK(Utils::allCaps("") == "");
}

TEST_CASE("downcases a string") {
CHECK(Utils::noCaps("TEST") == "test");
CHECK(Utils::noCaps("test") == "test");
CHECK(Utils::noCaps("UNDER_SCORE") == "under_score");
CHECK(Utils::noCaps("") == "");
}

TEST_CASE("removes punctuation from string") {
CHECK(Utils::removePunc("google.com") == "googlecom");
CHECK(Utils::removePunc("*&!((.#))") == "");
CHECK(Utils::removePunc("hello world") == "hello world");
}

TEST_CASE("flips a string") {
CHECK(Utils::flip("goof ball") == "ball goof");
CHECK(Utils::flip("foo") == "foo");
CHECK(Utils::flip("Foo bar baz.") == "baz bar Foo.");
}

TEST_CASE("excludes a number from a range") {
CHECK(Utils::randInRangeExclude(1, 2, 2) == 1);
CHECK(Utils::randInRangeExclude(1, 0, 0) == 1);
CHECK(Utils::randInRangeExclude(1, 1, 1) == NULL);
}
46 changes: 46 additions & 0 deletions test/word_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "doctest.h"

#include "word.cpp"


TEST_CASE("initialize member variables") {
Word w("gravy", "su");
CHECK(w.getVal() == "gravy");
CHECK(w.getFrequency() == 1);
CHECK(w.getStressPattern() == "su");

}

TEST_CASE("copy constructor") {
Word w("gravy", "su");

Word x = w;

CHECK(x.getVal() == "gravy");
CHECK(x.getFrequency() == 1);
CHECK(w.getStressPattern() == "su");

CHECK(&w != &x);
}

TEST_CASE("update frequency") {
Word w("gravy", "su");
w.incrementFrequency();

CHECK(w.getFrequency() == 2);
}

TEST_CASE("comparison operator") {
Word w("gravy", "su");
Word x("gravy", "su");

Word y("gravy", "uu");

Word z("notgravy", "su");
Word u("notgravy", "uu");

CHECK((w==x) == true);
CHECK((w==y) == true);
CHECK((w==z) == false);
CHECK((w==u) == false);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have to assert == true or ==false. Can't you just do CHECK(w==x); and CHECK(w!=z);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope cannot, at least not that I can tell

45 changes: 45 additions & 0 deletions test/wordlist_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "doctest.h"


#include "wordList.cpp"


TEST_SUITE("wordlist");

TEST_CASE("constructor") {
Word w("gravy", "su");
Word n("_NULL_", "");

WordList l(w);

CHECK( (l.getBase() == w) == true );
CHECK( l.getLeaders().size() == 1 );
CHECK( (l.getLeaders().at(0) == n) == true );
}

TEST_CASE("add leader") {
Word w("gravy", "su");
Word x("boat", "s");
Word y("train", "s");

WordList l(w);

l.addLeader(x);

CHECK( l.getLeaders().size() == 2);
CHECK( (l.getLeaders().at(1) == x) == true );

l.addLeader(y);

CHECK( l.getLeaders().size() == 3);
CHECK( (l.getLeaders().at(2) == y) == true );
}

TEST_CASE("pick leader") {
Word w("gravy", "su");

WordList l(w);
}


TEST_SUITE_END();