Skip to content

Commit

Permalink
Tests for JumpDrive
Browse files Browse the repository at this point in the history
  • Loading branch information
ericman314 committed Oct 30, 2018
1 parent 918f1d1 commit c1dbba5
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/src/classes/jumpDrive.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { System } from "./generic";

class Sector {
constructor(params, powerLevel = 0) {
constructor(params = {}, powerLevel = 0) {
this.level = params.level || Math.floor(powerLevel / 4);
this.offset = params.offset || 0;
}
Expand All @@ -17,7 +17,7 @@ class Sector {
If a sector has more power than it needs
*/
export default class JumpDrive extends System {
constructor(params) {
constructor(params = {}) {
super(params);
this.class = "JumpDrive";
this.type = "JumpDrive";
Expand Down
105 changes: 105 additions & 0 deletions server/tests/classes/jumpDrive.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// TODO: Figure out why we need import { Engine } what to do about it
import { Engine } from '../../src/classes/engine';
import { System } from "../../src/classes/generic";
import JumpDrive from '../../src/classes/jumpDrive';

describe('JumpDrive', () => {

test('should throw if called without the \'new\' operator', () => {
expect(() => { const j = JumpDrive(); }).toThrow(/Cannot call a class as a function/);
});

test('should extend System', () => {
expect(new JumpDrive()).toBeInstanceOf(System);
})

describe('constructor', () => {
test('should set default parameters', () => {
const j = new JumpDrive();
expect(j.name).toBe('Jump Drive');
expect(j.class).toBe('JumpDrive');
expect(j.type).toBe('JumpDrive');
expect(j.displayName).toBe('Jump Drive');
expect(j.simulatorId).toBeNull();
expect(j.power).toEqual({
power: 5,
powerLevels: [10, 16, 22, 28, 34, 40],
defaultLevel: 0
});
expect(j.env).toBe(0);
expect(j.activated).toBe(false);
});
});

describe('stealth factor', () => {
test.skip('should calculate the stealth factor', () => {
const j = new JumpDrive();
expect(j.stress).toBe(0);
j.setSectorOffset('fore', 0.3);
j.setSectorOffset('aft', 0.4);
j.setSectorOffset('starboard', 0.5);
j.setSectorOffset('port', 0.6);
expect(j.stealthFactor).toBe(0);
j.setActivated(true);
expect(j.stealthFactor).toBe(0.45);
});
});

describe('stress', () => {
test('should calculate the stress', () => {
const j = new JumpDrive();
expect(j.stress).toBe(0);
j.addSectorOffset('fore', 0.3);
j.addSectorOffset('aft', 0.4);
j.addSectorOffset('starboard', 0.5);
j.addSectorOffset('port', 0.6);
expect(j.stress).toBeCloseTo(0.45, 6);
});
});

describe('break', () => {
test('should deactivate jump drive', () => {
const j = new JumpDrive({ activated: true });
expect(j.activated).toBe(true);
j.break();
expect(j.activated).toBe(false);
});

test('should call super', () => {
const j = new JumpDrive();
expect(j.damage.damaged).toBe(false);
j.break();
expect(j.damage.damaged).toBe(true);
});
});

describe('setPower', () => {
test('should decrease env to the level indicated by the power', () => {
const j = new JumpDrive();

j.setEnv(5);
j.setPower(30);
expect(j.env).toBe(4);

j.setEnv(5);
j.setPower(20);
expect(j.env).toBe(2);

j.setPower(30);
expect(j.env).toBe(2);

j.setEnv(10);
j.setPower(60);
expect(j.env).toBe(6);

j.setPower(0);
expect(j.env).toBe(1);
});

test('should call super', () => {
const j = new JumpDrive();
j.setPower(30);
expect(j.power.power).toBe(30);
});
});
});

0 comments on commit c1dbba5

Please sign in to comment.