-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpile.test.ts
57 lines (52 loc) · 1.53 KB
/
pile.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
52
53
54
55
56
57
import { assert } from "chai";
import { GetCircle, GetSquare } from "../src/card";
import emitter from "../src/events";
import Pile from "../src/pile";
describe("Pile", () => {
describe(".top()", () => {
it("should be null initially", () => {
const pile = new Pile({ emitter });
assert.isNull(pile.top());
});
});
describe(".push([...])", () => {
it("should throw InvalidArgumentTypeError(Array)", () => {
try {
const pile = new Pile({ emitter });
// @ts-ignore
pile.push({});
assert.fail();
} catch (err: any) {
assert.equal(err.name, "InvalidArgumentTypeError");
assert.equal(err.type.name, "Array");
}
});
it("should throw NoCardSuppliedError when _cards_[] is empty", () => {
try {
const pile = new Pile({ emitter });
pile.push([]);
assert.fail();
} catch (err: any) {
assert.equal(err.name, "NoCardSuppliedError");
}
});
it("should throw LastCardMismatchError", () => {
try {
const pile = new Pile({ emitter });
const card = GetCircle({ value: 1 });
const card2 = GetSquare({ value: 2 });
pile.push([card]);
pile.push([card2]);
assert.fail();
} catch (err: any) {
assert.equal(err.name, "LastCardMismatchError");
}
});
it("should work", () => {
const pile = new Pile({ emitter });
const card = GetCircle({ value: 1 });
pile.push([card]);
assert.deepEqual(pile.top(), card);
});
});
});