-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
51 lines (44 loc) · 1.53 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Currency, ExchangeRate } from "./src/entity/currency";
import { Wallet } from "./src/entity/wallet";
import { Rate } from "./src/model/viewModel";
const assert = require('assert')
// helpers
let btc = new Currency('BTC', 'Bitcoin')
let eth = new Currency('ETH', 'Ethereum')
let btcToEth: Rate = {name: 'BTC->ETH', rate: 100}
let exRate = [btcToEth]
// test case
function testCreateWallet() {
let wallet = new Wallet(btc)
let assertWallet = new Wallet(btc, 100)
wallet.deposit(100)
assert.strictEqual(wallet.getCurrency(), assertWallet.getCurrency())
assert.strictEqual(wallet.getAmount(), assertWallet.getAmount())
console.log(`running: ${testCreateWallet.name} ⭕`)
}
function testGetAmount() {
let wallet = new Wallet(btc)
wallet.deposit(45)
assert.strictEqual(wallet.getAmount(), 45)
console.log(`running: ${testGetAmount.name} ⭕`)
}
function testTranfer() {
let walletA = new Wallet(btc, 100)
let walletB = new Wallet(btc)
walletA.tranfer(walletB, 45, exRate)
assert.strictEqual(walletB.getAmount(), 45)
assert.strictEqual(walletA.getAmount(), 55)
console.log(`running: ${testTranfer.name} ⭕`)
}
function testTranferChangeRate() {
let walletA = new Wallet(btc, 100)
let walletB = new Wallet(eth)
walletA.tranfer(walletB, 45, exRate)
assert.strictEqual(walletB.getAmount(), 4500)
assert.strictEqual(walletA.getAmount(), 55)
console.log(`running: ${testTranferChangeRate.name} ⭕`)
}
testCreateWallet()
testGetAmount()
testTranfer()
testTranferChangeRate()