Skip to content

Commit

Permalink
fix(levels): can no longer unload levels if higher levels are loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
moutella committed Sep 4, 2021
1 parent 51c5eaf commit 8862528
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
14 changes: 12 additions & 2 deletions che/che.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ export default class Che {
this._level1 = new CheL1(this);
}

cleanL1() {
cleanL1(force = false) {
if (force) {
this.cleanL2(true);
} else if (this._level2) {
throw Error("You can't unload a level if a higher one is loaded.")
}
this._level1 = null;
}

Expand All @@ -186,7 +191,12 @@ export default class Che {
this._level2 = new CheL2(this);
}

cleanL2() {
cleanL2(force = false) {
if (force) {
this.cleanL3();
} else if (this._level3) {
throw Error("You can't unload a level if a higher one is loaded.")
}
this._level2 = null;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/che.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,35 @@ test('L3: Check if all opposites are less than nCurves', () => {
expect(che_base.level3.checkOpposites()).toBe(true);
})


test('CHE: Fail unload L1', () => {

expect(che_base.cleanL1).toThrow(Error);
})

test('CHE: Force unload L1', () => {
che_base.cleanL1(true);
expect(che_base.level1).toBe(null);
expect(che_base.level2).toBe(null);
expect(che_base.level3).toBe(null);
})

test('CHE: Fail unload L2', () => {
che_base.loadCheL1()
che_base.loadCheL2()
che_base.loadCheL3()
expect(che_base.cleanL2).toThrow(Error);
})

test('CHE: Force unload L2', () => {
che_base.cleanL2(true);
expect(che_base.level2).toBe(null);
expect(che_base.level3).toBe(null);
})

test('CHE: Unload L3', () => {
che_base.loadCheL2()
che_base.loadCheL3()
che_base.cleanL3()
expect(che_base.level3).toBe(null);
})
Expand Down

0 comments on commit 8862528

Please sign in to comment.