diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-13 23:30:18 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-13 23:31:17 +0100 |
commit | f3fb8be7db6de87dae40d41bd5597a735c800ca1 (patch) | |
tree | 1a061db04de8f5bb5a6b697fa56a9948f67fac2f /src/types-test.ts | |
parent | 200d83c3886149ebb3f018530302079e12a81f6b (diff) | |
download | wallet-core-f3fb8be7db6de87dae40d41bd5597a735c800ca1.tar.xz |
restructuring
Diffstat (limited to 'src/types-test.ts')
-rw-r--r-- | src/types-test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/types-test.ts b/src/types-test.ts new file mode 100644 index 000000000..3ebb1a5db --- /dev/null +++ b/src/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(); +}); |