aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-13 20:29:43 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-13 20:29:43 +0100
commit8f939a0e5831b2e447e43af452b481a967cd9495 (patch)
tree6d80448709bffed16c144b9993dce97ebdb6190e /lib
parent95ad4639a36f1050ce823332b4a38583d45c0c11 (diff)
downloadwallet-core-8f939a0e5831b2e447e43af452b481a967cd9495.tar.xz
more tests, better reports
Diffstat (limited to 'lib')
-rw-r--r--lib/wallet/types-test.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/wallet/types-test.ts b/lib/wallet/types-test.ts
new file mode 100644
index 000000000..3ebb1a5db
--- /dev/null
+++ b/lib/wallet/types-test.ts
@@ -0,0 +1,38 @@
+import {test, TestLib} from "testlib/talertest";
+import {Amounts} from "./types";
+import * as types from "./types";
+
+let amt = (value: number, fraction: number, currency: string): types.AmountJson => ({value, fraction, currency});
+
+test("amount addition (simple)", (t: TestLib) => {
+ let a1 = amt(1,0,"EUR");
+ let a2 = amt(1,0,"EUR");
+ let a3 = amt(2,0,"EUR");
+ t.assert(0 == types.Amounts.cmp(Amounts.add(a1, a2).amount, a3));
+ t.pass();
+});
+
+test("amount addition (saturation)", (t: TestLib) => {
+ let a1 = amt(1,0,"EUR");
+ let res = Amounts.add(Amounts.getMaxAmount("EUR"), a1);
+ t.assert(res.saturated);
+ t.pass();
+});
+
+test("amount subtraction (simple)", (t: TestLib) => {
+ let a1 = amt(2,5,"EUR");
+ let a2 = amt(1,0,"EUR");
+ let a3 = amt(1,5,"EUR");
+ t.assert(0 == types.Amounts.cmp(Amounts.sub(a1, a2).amount, a3));
+ t.pass();
+});
+
+test("amount subtraction (saturation)", (t: TestLib) => {
+ let a1 = amt(0,0,"EUR");
+ let a2 = amt(1,0,"EUR");
+ let res = Amounts.sub(a1, a2);
+ t.assert(res.saturated);
+ res = Amounts.sub(a1, a1);
+ t.assert(!res.saturated);
+ t.pass();
+});