mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 22:55:35 +00:00
Adding karma and unit tests to get started
This commit is contained in:
34
test/karma.conf.js
Normal file
34
test/karma.conf.js
Normal file
@@ -0,0 +1,34 @@
|
||||
// Karma configuration
|
||||
// Generated on Thu Jun 11 2015 19:39:40 GMT-0700 (PDT)
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['jasmine'],
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'../build/lib*.js',
|
||||
'../node_modules/angular-mocks/angular-mocks.js',
|
||||
'../build/app*.js',
|
||||
'tests/**/*.js'
|
||||
],
|
||||
// list of files to exclude
|
||||
exclude: [],
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {},
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['progress'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: false,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false
|
||||
});
|
||||
};
|
||||
66
test/tests/test-data.js
Normal file
66
test/tests/test-data.js
Normal file
@@ -0,0 +1,66 @@
|
||||
describe("Database", function() {
|
||||
|
||||
var shipProperties = ["grp", "name", "manufacturer", "class", "cost", "speed", "boost", "agility", "shields", "armour", "fuelcost", "mass"];
|
||||
|
||||
it("has ships and components", function() {
|
||||
expect(DB.ships).toBeDefined()
|
||||
expect(DB.components.common).toBeDefined();
|
||||
expect(DB.components.hardpoints).toBeDefined();
|
||||
expect(DB.components.internal).toBeDefined();
|
||||
expect(DB.components.bulkheads).toBeDefined();
|
||||
});
|
||||
|
||||
it("has unique IDs for every hardpoint", function() {
|
||||
var ids = {};
|
||||
var groups = DB.components.hardpoints;
|
||||
|
||||
for (var g in groups) {
|
||||
var group = groups[g];
|
||||
for (var i = 0; i < group.length; i++) {
|
||||
var id = group[i].id;
|
||||
expect(ids[id]).toBeFalsy('ID already exists: ' + id);
|
||||
expect(group[i].grp).toBeDefined('Hardpoint has no group defined, ID:' + id);
|
||||
ids[id] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("has valid internal components", function() {
|
||||
var ids = {};
|
||||
var groups = DB.components.internal;
|
||||
|
||||
for (var g in groups) {
|
||||
var group = groups[g];
|
||||
for (var i = 0; i < group.length; i++) {
|
||||
var id = group[i].id;
|
||||
expect(ids[id]).toBeFalsy('ID already exists: ' + id);
|
||||
expect(group[i].grp).toBeDefined('Internal component has no group defined, ID:' + id);
|
||||
ids[id] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("has data for every ship", function() {
|
||||
for (var s in DB.ships) {
|
||||
for (var p = 0; p < shipProperties.length; p++) {
|
||||
expect(DB.ships[s].properties[shipProperties[p]]).toBeDefined(shipProperties[p] + ' is missing for ' + s);
|
||||
}
|
||||
expect(DB.ships[s].slots.common.length).toEqual(7, s + ' is missing common slots');
|
||||
expect(DB.ships[s].defaults.common.length).toEqual(7, s + ' is missing common defaults');
|
||||
expect(DB.ships[s].slots.hardpoints.length).toEqual(DB.ships[s].defaults.hardpoints.length, s + ' hardpoint slots and defaults dont match');
|
||||
expect(DB.ships[s].slots.internal.length).toEqual(DB.ships[s].defaults.internal.length, s + ' hardpoint slots and defaults dont match');
|
||||
expect(DB.ships[s].retailCost).toBeGreaterThan(DB.ships[s].properties.cost, s + ' has invalid retail cost');
|
||||
expect(DB.components.bulkheads[s]).toBeDefined(s + ' is missing bulkheads');
|
||||
}
|
||||
});
|
||||
|
||||
it("has components with a group defined", function() {
|
||||
for (var i = 0; i < DB.components.common.length; i++) {
|
||||
var group = DB.components.common[i];
|
||||
for (var c in group) {
|
||||
expect(group[c].grp).toBeDefined('Common component has no group defined, Type: ' + i + ', ID: ' + c);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
35
test/tests/test-factory-ship.js
Normal file
35
test/tests/test-factory-ship.js
Normal file
@@ -0,0 +1,35 @@
|
||||
describe("Ship Factory", function() {
|
||||
|
||||
var Ship;
|
||||
|
||||
beforeEach(module('shipyard'));
|
||||
beforeEach(inject(['Ship', function (_Ship_) {
|
||||
Ship = _Ship_;
|
||||
}]));
|
||||
|
||||
it("can build all ships", function() {
|
||||
for (var s in DB.ships) {
|
||||
var shipData = DB.ships[s];
|
||||
var ship = new Ship(s, shipData.properties, shipData.slots);
|
||||
|
||||
for (p in shipData.properties) {
|
||||
expect(ship[p]).toEqual(shipData.properties[p], s + ' property [' + p + '] does not match when built');
|
||||
}
|
||||
|
||||
ship.buildWith(shipData.defaults);
|
||||
|
||||
expect(ship.totalCost).toEqual(shipData.retailCost, s + ' retail cost does not match default build cost');
|
||||
expect(ship.priorityBands[0].retracted).toBeGreaterThan(0);
|
||||
expect(ship.powerAvailable).toBeGreaterThan(0);
|
||||
expect(ship.unladenRange).toBeGreaterThan(0);
|
||||
expect(ship.ladenRange).toBeGreaterThan(0);
|
||||
expect(ship.cargoCapacity).toBeGreaterThan(0);
|
||||
expect(ship.fuelCapacity).toBeGreaterThan(0);
|
||||
expect(ship.unladenTotalRange).toBeGreaterThan(0);
|
||||
expect(ship.ladenTotalRange).toBeGreaterThan(0);
|
||||
expect(ship.shieldStrength).toBeGreaterThan(0);
|
||||
expect(ship.armourTotal).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user