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:
@@ -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