This repository has been archived by the owner on May 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMochaChaiTests.ts
108 lines (98 loc) · 3.18 KB
/
MochaChaiTests.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {Game} from './Model.js';
import {expect} from "chai";
import {Builder, Capabilities} from 'selenium-webdriver';
import "mocha"
let items = [
"item1",
"item2"
];
let gameInfo = {
"game_duration": 600,
"initial_credits":1000
};
let ships =
{
"ship1":{
"cargo_hold_size":99,
"position": "Planet1"
},
"ship2":{
"cargo_hold_size":105,
"position":"Planet2"
}
};
let planets = {
"Planet1": {
"available_items":{
"item1":{
"available": 100,
"buy_price": 3,
"sell_price": 7
}
},
"x": 99,
"y": 15
},
"Planet2": {
"available_items":{
"item2":{
"available": 100,
"buy_price": 30,
"sell_price": 70
}
},
"x": 99,
"y": 15
}
};
describe("changingCredits", () => {
let g : Game = new Game()
.setCredits(gameInfo.initial_credits)
.setShips(ships, items)
.setPlanets(planets, items)
.setItems(items)
.setTime(gameInfo.game_duration);
it("new game should have credits equal to initial credits", () => {
expect(g.credits).to.equal(gameInfo.initial_credits);
});
//Arrange
let planet1 = g.planets.get("Planet1");
let planet2 = g.planets.get("Planet2");
let ship1 = g.ships.get("ship1");
let ship2 = g.ships.get("ship2");
it("buying items while not having enough funds should fail", () =>{
g.performTrade(planet2, ship2, "item2", 100, 1);
expect(g.credits).to.equal(gameInfo.initial_credits);
});
it("you shouldnt be able to buy items from another planet", () =>{
g.performTrade(planet1, ship2, "item1", 1, 1);
expect(g.credits).to.equal(gameInfo.initial_credits);
g.performTrade(planet2, ship1, "item2", 1, 0);
expect(g.credits).to.equal(gameInfo.initial_credits);
g.performTrade(planet1, ship2, "item2", 1, 1);
expect(g.credits).to.equal(gameInfo.initial_credits);
g.performTrade(planet2, ship1, "item1", 1, 0);
expect(g.credits).to.equal(gameInfo.initial_credits);
});
it("you shouldn't be able to buy item on planet if availablity is 0", () => {
expect(planet1.items.get("item2").available).to.equal(0);
g.performTrade(planet1, ship1, "item2", 1, 0);
expect(g.credits).to.equal(gameInfo.initial_credits);
expect(planet2.items.get("item1").available).to.equal(0);
g.performTrade(planet2, ship2, "item1", 1, 1);
expect(g.credits).to.equal(gameInfo.initial_credits);
});
it("Cant sell item if you dont own it..", () => {
expect(ship1.items.get("item1") === 0);
g.performTrade(planet1, ship1, "item1", -1, 0);
});
it("You can buy items if you have money though :)", () => {
g.performTrade(planet1, ship1, "item1", 1, 0);
expect(g.credits).to.equal(gameInfo.initial_credits - planet1.items.get("item1").buy_price);
//restore to default
g.performTrade(planet1, ship1, "item1", -1, 0);
g.credits = gameInfo.initial_credits;
})
});
/*
*/