Add tests
This commit is contained in:
parent
38135762f6
commit
419e67f80a
@ -27,4 +27,77 @@ describe("World",
|
||||
rows.pop();
|
||||
expect(rows).toEqual(plan);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("actionTypes",
|
||||
function () {
|
||||
it("grow",
|
||||
function () {
|
||||
let critter = new life.Plant();
|
||||
let energy = critter.energy;
|
||||
life.actionTypes.grow(critter);
|
||||
expect(critter.energy).toBeGreaterThan(energy);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
describe("PlantEater",
|
||||
function () {
|
||||
it("constructor",
|
||||
function () {
|
||||
let pe = new life.PlantEater();
|
||||
expect('energy' in pe).toBe(true);
|
||||
expect(pe.energy).toBe(20);
|
||||
});
|
||||
it("act, reproduce",
|
||||
function () {
|
||||
let pe = new life.PlantEater();
|
||||
pe.energy = 65
|
||||
expect(pe.act({find: function (ch) { if (ch === " ") return "n"; } })).toEqual({ type: "reproduce", direction: "n" });
|
||||
|
||||
});
|
||||
it("act, eat",
|
||||
function () {
|
||||
let pe = new life.PlantEater();
|
||||
pe.energy = 20
|
||||
expect(pe.act({find: function (ch ) { if (ch === "*") return "n"; } })).toEqual({ type: "eat", direction: "n" });
|
||||
});
|
||||
it("act, move",
|
||||
function () {
|
||||
let pe = new life.PlantEater();
|
||||
expect(pe.act({find: function (ch) { if (ch === " ") return "n"; } })).toEqual({ type: "move", direction: "n" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("ExplodingBunnyRabbit",
|
||||
function () {
|
||||
it("constructor",
|
||||
function () {
|
||||
let pe = new life.ExplodingBunnyRabbit();
|
||||
expect('energy' in pe).toBe(true);
|
||||
expect(pe.energy).toBe(20);
|
||||
});
|
||||
it("act, reproduce",
|
||||
function () {
|
||||
let pe = new life.ExplodingBunnyRabbit();
|
||||
pe.energy = 65
|
||||
expect(pe.act({find: function (ch) { if (ch === " ") return "n"; } })).toEqual({ type: "reproduce", direction: "n" });
|
||||
|
||||
});
|
||||
it("act, eat",
|
||||
function () {
|
||||
let pe = new life.ExplodingBunnyRabbit();
|
||||
pe.energy = 20
|
||||
expect(pe.act({find: function (ch ) { if (ch === "*") return "n"; } })).toEqual({ type: "eat", direction: "n" });
|
||||
});
|
||||
it("act, move",
|
||||
function () {
|
||||
let pe = new life.ExplodingBunnyRabbit();
|
||||
expect(pe.act({find: function (ch) { if (ch === " ") return "n"; } })).toEqual({ type: "move", direction: "n" });
|
||||
});
|
||||
it("act, explode",
|
||||
function () {
|
||||
let pe = new life.ExplodingBunnyRabbit();
|
||||
expect(pe.act({find: function (ch) { if (ch === "O") return "n"; } })).toEqual({ type: "explode", direction: "n" });
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user