Commit 99c92aad authored by Sergej Chodarev's avatar Sergej Chodarev
Browse files

Add first tests for wall and post modules

parent 9ad56f6c
......@@ -3,5 +3,16 @@
#include "greatest.h"
#include "../post.h"
TEST like_post_increments_like_count() {
post_t *post = create_post("test");
like_post(post);
ASSERT_EQ(post->like_count, 1);
destroy_post(post);
PASS();
}
SUITE(test_post) {
RUN_TEST(like_post_increments_like_count);
}
......@@ -3,5 +3,50 @@
#include "greatest.h"
#include "../wall.h"
wall_t *create_wall_with_posts(int num_posts) {
char buffer[25];
wall_t *wall = create_wall();
for (int i = 1; i <= num_posts; i++) {
sprintf(buffer, "Post %d", i);
add_post(wall, create_post(buffer));
}
return wall;
}
TEST empty_wall_should_have_no_posts() {
wall_t *wall = create_wall();
ASSERT_EQ(get_post(wall, 0), NULL);
ASSERT_EQ(get_post(wall, 1), NULL);
destroy_wall(wall);
PASS();
}
TEST get_post_should_return_first_post() {
wall_t *wall = create_wall();
post_t *post1 = create_post("Post 1");
add_post(wall, post1);
ASSERT_EQ(get_post(wall, 1), post1);
destroy_wall(wall);
PASS();
}
TEST get_post_should_return_last_post() {
wall_t *wall = create_wall_with_posts(3);
post_t *post4 = create_post("Post 4");
add_post(wall, post4);
ASSERT_EQ(get_post(wall, 4), post4);
destroy_wall(wall);
PASS();
}
SUITE(test_wall) {
RUN_TEST(empty_wall_should_have_no_posts);
RUN_TEST(get_post_should_return_first_post);
RUN_TEST(get_post_should_return_last_post);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment