Skip to content

Commit

Permalink
Partial queue implentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade Meskill and Roy van de Water authored and Roy van de Water committed Dec 7, 2013
1 parent 2f9c8d0 commit aa1c25e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/char_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class CharQueue {
private:
int mSize;
Char *head;
// Char *head;

public:
CharQueue() {
Expand All @@ -17,20 +17,21 @@ class CharQueue {
return mSize;
}

char pop() {
char character = head->get_character();
head = head->get_next();
void pop() {
// char character = head->get_character();
// head = head->get_next();
// mSize--;
mSize--;
return character;
// return character;
}

void push(char character) {
Char *next = new Char(character);
Char *current = head;
while (mSize > 0 && !current->last()) {
current = current->get_next();
}
current->set_next(next);
// Char *next = new Char(character);
// Char *current = head;
// while (mSize > 0 && !current->last()) {
// current = current->get_next();
// }
// current->set_next(next);
mSize++;
}
};
Expand Down
Binary file modified test/a.out
Binary file not shown.
69 changes: 69 additions & 0 deletions test/char_queue_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../src/char_queue.h"
#include <assert.h>

class CharQueueTest {
public:
CharQueue *char_queue;

CharQueueTest() {
setup();
}

void setup() {
char_queue = new CharQueue();
}

void test_constructor() {
setup();
}

void test_push() {
setup();
char_queue->push('h');
}

void test_size_when_empty() {
setup();
assert( char_queue->size() == 0 );
}

void test_size_with_one_item() {
setup();
char_queue->push('h');
assert( char_queue->size() == 1 );
}

void test_size_with_two_items() {
setup();
char_queue->push('h');
char_queue->push('x');
assert( char_queue->size() == 2 );
}

void test_size_after_a_push_and_a_pop() {
setup();
char_queue->push('h');
char_queue->pop();
assert( char_queue->size() == 0 );
}

void test_size_after_two_pushes_and_a_pop() {
setup();
char_queue->push('h');
char_queue->push('x');
char_queue->pop();
assert( char_queue->size() == 1 );
}
};


void char_queue_test(){
CharQueueTest *test = new CharQueueTest();
test->test_constructor();
test->test_push();
test->test_size_when_empty();
test->test_size_with_one_item();
test->test_size_with_two_items();
test->test_size_after_a_push_and_a_pop();
test->test_size_after_two_pushes_and_a_pop();
}
4 changes: 2 additions & 2 deletions test/char_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CharTest {
character->set_next(next_character);
}

void test_char_constructor() {
void test_constructor() {
setup();
assert( character->get_character() == 'h' );
assert( next_character->get_character() == 'n' );
Expand All @@ -41,7 +41,7 @@ class CharTest {

void char_test(){
CharTest *test = new CharTest();
test->test_char_constructor();
test->test_constructor();
test->test_char_is_last_when_last();
test->test_char_is_last_when_not_last();
test->test_get_next_when_not_last();
Expand Down
2 changes: 2 additions & 0 deletions test/run_all.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "char_test.h"
#include "char_queue_test.h"

int main() {
char_test();
char_queue_test();
return 0;
}

0 comments on commit aa1c25e

Please sign in to comment.