diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-11 08:54:52 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2010-12-11 08:54:52 +0100 |
commit | 1de8e6eed4c3b5d48e2175e660b50840996cbf63 (patch) | |
tree | 06be3b6e9a2e7315a79415f7117d7837b5809e9f | |
parent | 92c5013d6fcc63ecf615d1e0e2acfe570175a6de (diff) |
Added unit test framework.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | server/SConstruct | 4 | ||||
-rw-r--r-- | server/tests/SConscript | 11 | ||||
-rw-r--r-- | server/tests/calculate_score.cpp | 27 | ||||
-rw-r--r-- | server/tests/test_framework.cpp | 1 |
5 files changed, 45 insertions, 0 deletions
@@ -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 <boost/test/unit_test.hpp> + +#include <boost/assign/list_of.hpp> +using boost::assign::list_of; + +#include "../player.h" + +BOOST_AUTO_TEST_CASE(tsumo_tanyao) { + Player player; + player.client = make_shared<ClientDumb>(); + 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 <boost/test/included/unit_test.hpp> |