From 1de8e6eed4c3b5d48e2175e660b50840996cbf63 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 11 Dec 2010 08:54:52 +0100 Subject: Added unit test framework. --- .gitignore | 2 ++ server/SConstruct | 4 ++++ server/tests/SConscript | 11 +++++++++++ server/tests/calculate_score.cpp | 27 +++++++++++++++++++++++++++ server/tests/test_framework.cpp | 1 + 5 files changed, 45 insertions(+) create mode 100644 server/tests/SConscript create mode 100644 server/tests/calculate_score.cpp create mode 100644 server/tests/test_framework.cpp diff --git a/.gitignore b/.gitignore index 57eea40..a807d2a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ .sconsign.dblite client/aotenjou server/aotenjoud +*.test +*.passed *.suo *.depend diff --git a/server/SConstruct b/server/SConstruct index 67bb36a..09f34c7 100644 --- a/server/SConstruct +++ b/server/SConstruct @@ -25,4 +25,8 @@ Export('env') env.Program('aotenjoud', Glob('*.cpp') + Glob('../common/*.cpp')) +env.SConscript('tests/SConscript') + +Default('aotenjoud') + # vim: syn=python diff --git a/server/tests/SConscript b/server/tests/SConscript new file mode 100644 index 0000000..b6c3bea --- /dev/null +++ b/server/tests/SConscript @@ -0,0 +1,11 @@ +Import('env') + +test_bld = Builder( + action = '$SOURCE -e stdout && touch $TARGET', + emitter = lambda target, source, env: (target[0].name + '.passed', env.Program(target[0].name + '.test', source)) +) + +env.Append(BUILDERS = {'Test' : test_bld}) + +env.Test('calculate_score', ['calculate_score.cpp', 'test_framework.cpp', + '../player.cpp', '../client.cpp', '../connection.cpp', '../hand.cpp', '../score.cpp'] + Glob('../../common/*.cpp')) diff --git a/server/tests/calculate_score.cpp b/server/tests/calculate_score.cpp new file mode 100644 index 0000000..cb4e0f2 --- /dev/null +++ b/server/tests/calculate_score.cpp @@ -0,0 +1,27 @@ +#define BOOST_TEST_MODULE +#include + +#include +using boost::assign::list_of; + +#include "../player.h" + +BOOST_AUTO_TEST_CASE(tsumo_tanyao) { + Player player; + player.client = make_shared(); + player.round_start(0); + + player.hand = list_of + (Tile::Man_2)(Tile::Man_2)(Tile::Man_2) + (Tile::Pin_2)(Tile::Pin_3)(Tile::Pin_4) + (Tile::Sou_2)(Tile::Sou_2)(Tile::Sou_2) + (Tile::Man_8)(Tile::Man_8); + + player.declare_tsumo(); + + BOOST_CHECK_EQUAL(player.won, true); + BOOST_CHECK_EQUAL(player.won_value.yaku, 2); + BOOST_CHECK_EQUAL(player.won_value.fu, 28); + BOOST_CHECK_EQUAL(player.won_value.tsumo(), 500); + BOOST_CHECK_EQUAL(player.won_value.tsumo_east(), 1000); +} diff --git a/server/tests/test_framework.cpp b/server/tests/test_framework.cpp new file mode 100644 index 0000000..67373e9 --- /dev/null +++ b/server/tests/test_framework.cpp @@ -0,0 +1 @@ +#include -- cgit v1.2.3