mirror of
https://github.com/wassname/cardsforscience.git
synced 2026-06-27 18:42:09 +08:00
Converted to es6 imports and exports
This commit is contained in:
+25
-25
@@ -1,25 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
|
||||
|
||||
describe('cards for science', function() {
|
||||
|
||||
|
||||
describe('Phone list view', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
browser.get('index.html');
|
||||
});
|
||||
|
||||
|
||||
// it('should filter the phone list as a user types into the search box', function() {
|
||||
//
|
||||
// var lastCards = element.all(by.css('#lastCards .card'));
|
||||
// expect(lastCards.count()).toBe(3);
|
||||
//
|
||||
// var query = element(by.repeater('r in rc.cards'));
|
||||
// query.click();
|
||||
// expect(lastCards.count()).toBe(4);
|
||||
// });
|
||||
});
|
||||
});
|
||||
'use strict';
|
||||
|
||||
/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
|
||||
|
||||
describe('cards for science', function() {
|
||||
|
||||
|
||||
describe('Phone list view', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
browser.get('index.html');
|
||||
});
|
||||
|
||||
|
||||
// it('should filter the phone list as a user types into the search box', function() {
|
||||
//
|
||||
// var lastCards = element.all(by.css('#lastCards .card'));
|
||||
// expect(lastCards.count()).toBe(3);
|
||||
//
|
||||
// var query = element(by.repeater('r in rc.cards'));
|
||||
// query.click();
|
||||
// expect(lastCards.count()).toBe(4);
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
||||
+110
-110
@@ -1,110 +1,110 @@
|
||||
module.exports = function (config) {
|
||||
|
||||
// http://mike-ward.net/2015/09/07/tips-on-setting-up-karma-testing-with-webpack/
|
||||
var webpackConfig = require('../webpack.config.js');
|
||||
webpackConfig.entry = {};
|
||||
|
||||
config.set({
|
||||
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: {
|
||||
// noInfo: true,
|
||||
},
|
||||
basePath: '../',
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
// urlRoot: "/",
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: true,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['dots','html'],
|
||||
|
||||
htmlReporter: {
|
||||
outputFile: 'tests/units.html',
|
||||
|
||||
// Optional
|
||||
pageTitle: 'Unit Tests',
|
||||
subPageTitle: 'A sample project description'
|
||||
},
|
||||
|
||||
frameworks: ['jasmine'],
|
||||
|
||||
browsers: [
|
||||
'Chrome',
|
||||
// 'Firefox'
|
||||
],
|
||||
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: false,
|
||||
|
||||
plugins: [
|
||||
require('karma-sourcemap-loader'),
|
||||
require("karma-webpack"),
|
||||
require('karma-jasmine'),
|
||||
require('karma-ng-html2js-preprocessor'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-firefox-launcher'),
|
||||
"karma-jasmine-html-reporter-livereload" // displays html summary on debug page
|
||||
],
|
||||
|
||||
|
||||
preprocessors: {
|
||||
// './build/clientapp.bundle.js': ['webpack','sourcemap'],
|
||||
'./src/index.js': ['webpack','sourcemap'],
|
||||
// './src/js/rules.js': ['webpack','sourcemap'],
|
||||
"*.html": ["ng-html2js"]
|
||||
},
|
||||
|
||||
// ngHtml2JsPreprocessor: {
|
||||
// // If your build process changes the path to your templates,
|
||||
// // use stripPrefix and prependPrefix to adjust it.
|
||||
// // stripPrefix: "source/path/to/templates/.*/",
|
||||
// // prependPrefix: "web/path/to/templates/",
|
||||
//
|
||||
// // the name of the Angular module to create
|
||||
// moduleName: "cardsForScience.templates"
|
||||
// },
|
||||
|
||||
|
||||
// use this to fix server 404 errors. Karma server everything at /base
|
||||
proxies: {
|
||||
'/json/': '/base/json/'
|
||||
},
|
||||
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
|
||||
// dependencies
|
||||
|
||||
// these are for Module('')
|
||||
'node_modules/angular/angular.js',
|
||||
'node_modules/angular-mocks/angular-mocks.js',
|
||||
|
||||
// chai for rule tests
|
||||
'node_modules/chai/chai.js',
|
||||
|
||||
// files to test
|
||||
'./src/index.js', // load in webpack entry point
|
||||
'src/js/rules.js',
|
||||
'test/unit/**/*.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
exclude: [],
|
||||
});
|
||||
};
|
||||
module.exports = function (config) {
|
||||
|
||||
// http://mike-ward.net/2015/09/07/tips-on-setting-up-karma-testing-with-webpack/
|
||||
var webpackConfig = require('../webpack.config.js');
|
||||
webpackConfig.entry = {};
|
||||
|
||||
config.set({
|
||||
|
||||
webpack: webpackConfig,
|
||||
webpackMiddleware: {
|
||||
// noInfo: true,
|
||||
},
|
||||
basePath: '../',
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
// urlRoot: "/",
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: true,
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['dots','html'],
|
||||
|
||||
htmlReporter: {
|
||||
outputFile: 'tests/units.html',
|
||||
|
||||
// Optional
|
||||
pageTitle: 'Unit Tests',
|
||||
subPageTitle: 'A sample project description'
|
||||
},
|
||||
|
||||
frameworks: ['jasmine'],
|
||||
|
||||
browsers: [
|
||||
'Chrome',
|
||||
// 'Firefox'
|
||||
],
|
||||
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: false,
|
||||
|
||||
plugins: [
|
||||
require('karma-sourcemap-loader'),
|
||||
require("karma-webpack"),
|
||||
require('karma-jasmine'),
|
||||
require('karma-ng-html2js-preprocessor'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-firefox-launcher'),
|
||||
"karma-jasmine-html-reporter-livereload" // displays html summary on debug page
|
||||
],
|
||||
|
||||
|
||||
preprocessors: {
|
||||
// './build/clientapp.bundle.js': ['webpack','sourcemap'],
|
||||
'./src/index.js': ['webpack','sourcemap'],
|
||||
// './src/js/rules.js': ['webpack','sourcemap'],
|
||||
"*.html": ["ng-html2js"]
|
||||
},
|
||||
|
||||
// ngHtml2JsPreprocessor: {
|
||||
// // If your build process changes the path to your templates,
|
||||
// // use stripPrefix and prependPrefix to adjust it.
|
||||
// // stripPrefix: "source/path/to/templates/.*/",
|
||||
// // prependPrefix: "web/path/to/templates/",
|
||||
//
|
||||
// // the name of the Angular module to create
|
||||
// moduleName: "cardsForScience.templates"
|
||||
// },
|
||||
|
||||
|
||||
// use this to fix server 404 errors. Karma server everything at /base
|
||||
proxies: {
|
||||
'/json/': '/base/json/'
|
||||
},
|
||||
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
|
||||
// dependencies
|
||||
|
||||
// these are for Module('')
|
||||
'node_modules/angular/angular.js',
|
||||
'node_modules/angular-mocks/angular-mocks.js',
|
||||
|
||||
// chai for rule tests
|
||||
'node_modules/chai/chai.js',
|
||||
|
||||
// files to test
|
||||
'./src/index.js', // load in webpack entry point
|
||||
'src/js/rules.js',
|
||||
'test/unit/**/*.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
exclude: [],
|
||||
});
|
||||
};
|
||||
|
||||
+22
-22
@@ -1,22 +1,22 @@
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
|
||||
specs: [
|
||||
'e2e/*.js'
|
||||
],
|
||||
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
|
||||
chromeOnly: true,
|
||||
|
||||
baseUrl: 'http://localhost:8080/',
|
||||
|
||||
framework: 'jasmine',
|
||||
|
||||
jasmineNodeOpts: {
|
||||
defaultTimeoutInterval: 30000
|
||||
}
|
||||
};
|
||||
|
||||
exports.config = {
|
||||
allScriptsTimeout: 11000,
|
||||
|
||||
specs: [
|
||||
'e2e/*.js'
|
||||
],
|
||||
|
||||
capabilities: {
|
||||
'browserName': 'chrome'
|
||||
},
|
||||
|
||||
chromeOnly: true,
|
||||
|
||||
baseUrl: 'http://localhost:8080/',
|
||||
|
||||
framework: 'jasmine',
|
||||
|
||||
jasmineNodeOpts: {
|
||||
defaultTimeoutInterval: 30000
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for controllers go here */
|
||||
describe('cardsForScience controllers', function () {
|
||||
var $controller;
|
||||
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
toEqualData: function(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var passed = angular.equals(actual, expected);
|
||||
return {
|
||||
pass: passed,
|
||||
message: 'Expected "' + actual + '"' + (passed ? '' : ' not') + ' to angular.equals "' + expected + '"'
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
beforeEach(module('cardsForScience'));
|
||||
beforeEach(inject(function (_$controller_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$controller = _$controller_;
|
||||
}));
|
||||
|
||||
describe('CardController', function () {
|
||||
var $scope, controller;
|
||||
|
||||
beforeEach(function () {
|
||||
$scope = {};
|
||||
controller = $controller('CardController',{$scope:$scope});
|
||||
});
|
||||
|
||||
it('should have cards', function () {
|
||||
expect(controller.cards).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be visible', function () {
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isVisible(item)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be isAvailable', function () {
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isAvailable(item)).toBeDefined();
|
||||
});
|
||||
|
||||
// onDrop
|
||||
});
|
||||
|
||||
});
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for controllers go here */
|
||||
describe('cardsForScience controllers', function () {
|
||||
var $controller;
|
||||
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
toEqualData: function(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
var passed = angular.equals(actual, expected);
|
||||
return {
|
||||
pass: passed,
|
||||
message: 'Expected "' + actual + '"' + (passed ? '' : ' not') + ' to angular.equals "' + expected + '"'
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
beforeEach(module('cardsForScience'));
|
||||
beforeEach(inject(function (_$controller_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$controller = _$controller_;
|
||||
}));
|
||||
|
||||
describe('CardController', function () {
|
||||
var $scope, controller;
|
||||
|
||||
beforeEach(function () {
|
||||
$scope = {};
|
||||
controller = $controller('CardController',{$scope:$scope});
|
||||
});
|
||||
|
||||
it('should have cards', function () {
|
||||
expect(controller.cards).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be visible', function () {
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isVisible(item)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should be isAvailable', function () {
|
||||
var item = controller.cards[0];
|
||||
expect(controller.isAvailable(item)).toBeDefined();
|
||||
});
|
||||
|
||||
// onDrop
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
+38
-38
@@ -1,38 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for directives go here */
|
||||
|
||||
describe('directives', function () {
|
||||
var $compile,
|
||||
$rootScope;
|
||||
|
||||
// Load the myApp module, which contains the directive
|
||||
beforeEach(module('cardsForScience'));
|
||||
// beforeEach(module('Rules'));
|
||||
|
||||
// Store references to $rootScope and $compile
|
||||
// so they are available to all tests in this describe block
|
||||
beforeEach(inject(function (_$compile_, _$rootScope_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$compile = _$compile_;
|
||||
$rootScope = _$rootScope_;
|
||||
}));
|
||||
|
||||
// it('Replaces the element with the appropriate content', function () {
|
||||
// // define a rule for testing
|
||||
// $rootScope.rule = Rules.rules[0];
|
||||
//
|
||||
// // Compile a piece of HTML containing the directive
|
||||
// var element = $compile('<div cfs-rule="rule" ng-model="rule"></div>')($rootScope);
|
||||
//
|
||||
// // fire all the watches, so the scope expressions will be evaluated
|
||||
// // $rootScope.$digest();
|
||||
// $rootScope.$apply();
|
||||
//
|
||||
// // Check that the compiled element contains the templated content
|
||||
// var html = element.html();
|
||||
// expect(html).toContain("<select");
|
||||
// expect(html).toContain("<option");
|
||||
// expect(html).toContain("Next card must not have the same");
|
||||
// });
|
||||
});
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for directives go here */
|
||||
|
||||
describe('directives', function () {
|
||||
var $compile,
|
||||
$rootScope;
|
||||
|
||||
// Load the myApp module, which contains the directive
|
||||
beforeEach(module('cardsForScience'));
|
||||
// beforeEach(module('Rules'));
|
||||
|
||||
// Store references to $rootScope and $compile
|
||||
// so they are available to all tests in this describe block
|
||||
beforeEach(inject(function (_$compile_, _$rootScope_) {
|
||||
// The injector unwraps the underscores (_) from around the parameter names when matching
|
||||
$compile = _$compile_;
|
||||
$rootScope = _$rootScope_;
|
||||
}));
|
||||
|
||||
// it('Replaces the element with the appropriate content', function () {
|
||||
// // define a rule for testing
|
||||
// $rootScope.rule = Rules.rules[0];
|
||||
//
|
||||
// // Compile a piece of HTML containing the directive
|
||||
// var element = $compile('<div cfs-rule="rule" ng-model="rule"></div>')($rootScope);
|
||||
//
|
||||
// // fire all the watches, so the scope expressions will be evaluated
|
||||
// // $rootScope.$digest();
|
||||
// $rootScope.$apply();
|
||||
//
|
||||
// // Check that the compiled element contains the templated content
|
||||
// var html = element.html();
|
||||
// expect(html).toContain("<select");
|
||||
// expect(html).toContain("<option");
|
||||
// expect(html).toContain("Next card must not have the same");
|
||||
// });
|
||||
});
|
||||
|
||||
+53
-53
@@ -1,53 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
|
||||
describe('filter', function () {
|
||||
|
||||
beforeEach(
|
||||
module('cardsForScience')
|
||||
);
|
||||
|
||||
describe('niceNumber', function () {
|
||||
it('should make numbers human readable',
|
||||
inject(function (niceNumberFilter) {
|
||||
expect(niceNumberFilter(100000000)).toBe("100.0M");
|
||||
expect(niceNumberFilter(10000)).toBe("10.0k");
|
||||
expect(niceNumberFilter(0.000000001)).toBe(1e-9);
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('niceTime', function () {
|
||||
it('should make time human readable',
|
||||
inject(function (niceTimeFilter) {
|
||||
expect(niceTimeFilter(100000000)).toBe("1 day, 3 h, 46 min, 40 s");
|
||||
expect(niceTimeFilter(10000)).toBe("10 s");
|
||||
expect(niceTimeFilter(0.000000001)).toBe("1 s");
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('currency', function () {
|
||||
it('should make currency human readable',
|
||||
inject(function (currencyFilter) {
|
||||
expect(currencyFilter(100000000)).toBe("JTN 100.0M");
|
||||
expect(currencyFilter(10000)).toBe("JTN 10.0k");
|
||||
expect(currencyFilter(0.000000001)).toBe('JTN 1e-9');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('reverse', function () {
|
||||
it('should reverse',
|
||||
inject(function (reverseFilter) {
|
||||
expect(reverseFilter([1,2,3])[0]).toBe(3);
|
||||
expect(reverseFilter([1,2,3])[1]).toBe(2);
|
||||
expect(reverseFilter([1,2,3])[2]).toBe(1);
|
||||
expect(reverseFilter([]).length).toBe(0);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[0].i).toBe(3);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[1].i).toBe(2);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[2].i).toBe(1);
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
|
||||
describe('filter', function () {
|
||||
|
||||
beforeEach(
|
||||
module('cardsForScience')
|
||||
);
|
||||
|
||||
describe('niceNumber', function () {
|
||||
it('should make numbers human readable',
|
||||
inject(function (niceNumberFilter) {
|
||||
expect(niceNumberFilter(100000000)).toBe("100.0M");
|
||||
expect(niceNumberFilter(10000)).toBe("10.0k");
|
||||
expect(niceNumberFilter(0.000000001)).toBe(1e-9);
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('niceTime', function () {
|
||||
it('should make time human readable',
|
||||
inject(function (niceTimeFilter) {
|
||||
expect(niceTimeFilter(100000000)).toBe("1 day, 3 h, 46 min, 40 s");
|
||||
expect(niceTimeFilter(10000)).toBe("10 s");
|
||||
expect(niceTimeFilter(0.000000001)).toBe("1 s");
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
describe('currency', function () {
|
||||
it('should make currency human readable',
|
||||
inject(function (currencyFilter) {
|
||||
expect(currencyFilter(100000000)).toBe("JTN 100.0M");
|
||||
expect(currencyFilter(10000)).toBe("JTN 10.0k");
|
||||
expect(currencyFilter(0.000000001)).toBe('JTN 1e-9');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('reverse', function () {
|
||||
it('should reverse',
|
||||
inject(function (reverseFilter) {
|
||||
expect(reverseFilter([1,2,3])[0]).toBe(3);
|
||||
expect(reverseFilter([1,2,3])[1]).toBe(2);
|
||||
expect(reverseFilter([1,2,3])[2]).toBe(1);
|
||||
expect(reverseFilter([]).length).toBe(0);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[0].i).toBe(3);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[1].i).toBe(2);
|
||||
expect(reverseFilter([{i:1,2:2},{i:2},{i:3}])[2].i).toBe(1);
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
+127
-127
@@ -1,127 +1,127 @@
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
var allCards;
|
||||
|
||||
|
||||
describe('Rules', function () {
|
||||
var card, lastCards,Rule,rules;
|
||||
beforeEach(module('cardsForScience'));
|
||||
beforeEach(inject(function (game) {
|
||||
allCards=game.cards;
|
||||
lastCards = _.sampleSize(allCards,4);
|
||||
card = _.sample(allCards);
|
||||
Rule=game.Rule;
|
||||
rules=game.rules;
|
||||
}));
|
||||
|
||||
describe('Rule', function () {
|
||||
it('should test false on false', function () {
|
||||
var rule = new Rule('1','1',function(){return false;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test false on assertion error', function () {
|
||||
var rule = new Rule('2','2',function(){return chai.expect(1).to.equal(0);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test true on assertion', function () {
|
||||
var rule = new Rule('3','3',function(){return chai.expect(1).to.equal(1);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should test true on true', function () {
|
||||
var rule = new Rule('4','4',function(){return true;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should throw test on error', function () {
|
||||
var rule = new Rule('5','5',function(){throw new Error('test');return true;},{},{},[]);
|
||||
expect(function(){
|
||||
rule.test(card,lastCards,allCards);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
describe('Each rule', function () {
|
||||
Rules.rules.forEach(function(rule){
|
||||
describe('rule: "'+rule.key+'"', function () {
|
||||
|
||||
it('should describeVariations', function () {
|
||||
var desc = rule.describeVariations();
|
||||
expect(desc instanceof Array).toBe(true);
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
|
||||
it('should describeOptions', function () {
|
||||
var desc = rule.describeOptions();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should set options', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.setOptions({a24tgsdgtg43t5fd:1});
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
it('should randomize', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.randomize();
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
|
||||
for (var option in rule.optionDefaults) {
|
||||
if (rule.optionDefaults.hasOwnProperty(option)) {
|
||||
var def = rule.optionDefaults[option];
|
||||
var vals = rule.optionDesc[option].possibleVals;
|
||||
it('defaults should be in possible vals '+option,function(){
|
||||
expect(vals).toEqual(jasmine.arrayContaining([def]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// now check each rule permutation
|
||||
rule.optionsPossible.forEach(function(options){
|
||||
|
||||
describe('rule: "'+rule.describe()+'"', function () {
|
||||
beforeEach(function () {
|
||||
rule.setOptions(options);
|
||||
});
|
||||
it('should describe itself', function () {
|
||||
var desc = rule.describe();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should test', function () {
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
Boolean(res);
|
||||
});
|
||||
it('should genHints', function () {
|
||||
var hints = rule.genHints();
|
||||
expect(hints instanceof Array).toBe(true);
|
||||
expect(hints.length).toBeGreaterThan(0);
|
||||
expect(hints.join('')).not.toContain(/[{}]+/);
|
||||
});
|
||||
describe('simulation',function(){
|
||||
|
||||
it('should have more than 10% right and less than 60%',function(){
|
||||
var simulation=rule.simulateOne(options,allCards,52*2);
|
||||
expect(simulation).not.toEqual(undefined);
|
||||
expect(simulation.ratioRight).toBeLessThan(0.6);
|
||||
expect(simulation.ratioRight).toBeGreaterThan(0.1);
|
||||
expect(simulation.error).toBe(0);
|
||||
// if (simulation.wrong){
|
||||
// expect(_.uniq(simulation.wrongs)[0].length).toBeGreaterThan(0);
|
||||
// }
|
||||
});
|
||||
});
|
||||
// it should give reasons
|
||||
// it should not give errors
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
'use strict';
|
||||
|
||||
/* jasmine specs for filters go here */
|
||||
var allCards;
|
||||
|
||||
|
||||
describe('Rules', function () {
|
||||
var card, lastCards,Rule,rules;
|
||||
beforeEach(module('cardsForScience'));
|
||||
beforeEach(inject(function (game) {
|
||||
allCards=game.cards;
|
||||
lastCards = _.sampleSize(allCards,4);
|
||||
card = _.sample(allCards);
|
||||
Rule=game.Rule;
|
||||
rules=game.rules;
|
||||
}));
|
||||
|
||||
describe('Rule', function () {
|
||||
it('should test false on false', function () {
|
||||
var rule = new Rule('1','1',function(){return false;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test false on assertion error', function () {
|
||||
var rule = new Rule('2','2',function(){return chai.expect(1).to.equal(0);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
it('should test true on assertion', function () {
|
||||
var rule = new Rule('3','3',function(){return chai.expect(1).to.equal(1);},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should test true on true', function () {
|
||||
var rule = new Rule('4','4',function(){return true;},{},{},[]);
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
it('should throw test on error', function () {
|
||||
var rule = new Rule('5','5',function(){throw new Error('test');return true;},{},{},[]);
|
||||
expect(function(){
|
||||
rule.test(card,lastCards,allCards);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
describe('Each rule', function () {
|
||||
Rules.rules.forEach(function(rule){
|
||||
describe('rule: "'+rule.key+'"', function () {
|
||||
|
||||
it('should describeVariations', function () {
|
||||
var desc = rule.describeVariations();
|
||||
expect(desc instanceof Array).toBe(true);
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
|
||||
it('should describeOptions', function () {
|
||||
var desc = rule.describeOptions();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should set options', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.setOptions({a24tgsdgtg43t5fd:1});
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
it('should randomize', function () {
|
||||
var opts1 = rule.options;
|
||||
var opts = rule.randomize();
|
||||
expect(typeof opts).toBe('object');
|
||||
expect(opts).not.toEqual(opts1);
|
||||
});
|
||||
|
||||
for (var option in rule.optionDefaults) {
|
||||
if (rule.optionDefaults.hasOwnProperty(option)) {
|
||||
var def = rule.optionDefaults[option];
|
||||
var vals = rule.optionDesc[option].possibleVals;
|
||||
it('defaults should be in possible vals '+option,function(){
|
||||
expect(vals).toEqual(jasmine.arrayContaining([def]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// now check each rule permutation
|
||||
rule.optionsPossible.forEach(function(options){
|
||||
|
||||
describe('rule: "'+rule.describe()+'"', function () {
|
||||
beforeEach(function () {
|
||||
rule.setOptions(options);
|
||||
});
|
||||
it('should describe itself', function () {
|
||||
var desc = rule.describe();
|
||||
expect(typeof desc).toBe('string');
|
||||
expect(desc).not.toContain(/[{}]+/);
|
||||
});
|
||||
it('should test', function () {
|
||||
var res = rule.test(card,lastCards,allCards);
|
||||
Boolean(res);
|
||||
});
|
||||
it('should genHints', function () {
|
||||
var hints = rule.genHints();
|
||||
expect(hints instanceof Array).toBe(true);
|
||||
expect(hints.length).toBeGreaterThan(0);
|
||||
expect(hints.join('')).not.toContain(/[{}]+/);
|
||||
});
|
||||
describe('simulation',function(){
|
||||
|
||||
it('should have more than 10% right and less than 60%',function(){
|
||||
var simulation=rule.simulateOne(options,allCards,52*2);
|
||||
expect(simulation).not.toEqual(undefined);
|
||||
expect(simulation.ratioRight).toBeLessThan(0.6);
|
||||
expect(simulation.ratioRight).toBeGreaterThan(0.1);
|
||||
expect(simulation.error).toBe(0);
|
||||
// if (simulation.wrong){
|
||||
// expect(_.uniq(simulation.wrongs)[0].length).toBeGreaterThan(0);
|
||||
// }
|
||||
});
|
||||
});
|
||||
// it should give reasons
|
||||
// it should not give errors
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+28
-28
@@ -1,28 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
describe('services', function () {
|
||||
|
||||
//load modules
|
||||
beforeEach(module('cardsForScience'));
|
||||
|
||||
|
||||
// Test service availability
|
||||
describe('game', function () {
|
||||
it('should exist', inject(function (game) {
|
||||
expect(game).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
// describe('detector', function () {
|
||||
// it('should exist', inject(function (detector) {
|
||||
// expect(detector).toBeDefined();
|
||||
// }));
|
||||
// });
|
||||
|
||||
describe('lab', function () {
|
||||
it('should exist', inject(function (lab) {
|
||||
expect(lab).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
'use strict';
|
||||
|
||||
describe('services', function () {
|
||||
|
||||
//load modules
|
||||
beforeEach(module('cardsForScience'));
|
||||
|
||||
|
||||
// Test service availability
|
||||
describe('game', function () {
|
||||
it('should exist', inject(function (game) {
|
||||
expect(game).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
// describe('detector', function () {
|
||||
// it('should exist', inject(function (detector) {
|
||||
// expect(detector).toBeDefined();
|
||||
// }));
|
||||
// });
|
||||
|
||||
describe('lab', function () {
|
||||
it('should exist', inject(function (lab) {
|
||||
expect(lab).toBeDefined();
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user