summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/SConscript11
-rw-r--r--tests/calculate_score.cpp47
-rw-r--r--tests/test_framework.cpp1
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/SConscript b/tests/SConscript
new file mode 100644
index 0000000..bba628c
--- /dev/null
+++ b/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',
+ '../src/player.cpp', '../src/client.cpp', '../src/connection.cpp', '../src/hand.cpp', '../src/score.cpp'] + Glob('../common/*.cpp'))
diff --git a/tests/calculate_score.cpp b/tests/calculate_score.cpp
new file mode 100644
index 0000000..3555f01
--- /dev/null
+++ b/tests/calculate_score.cpp
@@ -0,0 +1,47 @@
+#define BOOST_TEST_MODULE calculate_score
+#include <boost/test/unit_test.hpp>
+
+#include <boost/assign/list_of.hpp>
+using boost::assign::list_of;
+
+#include "../src/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, 32);
+ BOOST_CHECK_EQUAL(player.won_value.tsumo(), 700);
+ BOOST_CHECK_EQUAL(player.won_value.tsumo_east(), 1300);
+}
+
+BOOST_AUTO_TEST_CASE(ron_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);
+
+ player.declare_ron(Tile::Man_8);
+
+ BOOST_CHECK_EQUAL(player.won, true);
+ BOOST_CHECK_EQUAL(player.won_value.yaku, 1);
+ BOOST_CHECK_EQUAL(player.won_value.fu, 40);
+ BOOST_CHECK_EQUAL(player.won_value.ron(), 1300);
+ BOOST_CHECK_EQUAL(player.won_value.ron_east(), 2000);
+}
diff --git a/tests/test_framework.cpp b/tests/test_framework.cpp
new file mode 100644
index 0000000..67373e9
--- /dev/null
+++ b/tests/test_framework.cpp
@@ -0,0 +1 @@
+#include <boost/test/included/unit_test.hpp>