Skip to content

Instantly share code, notes, and snippets.

@waynelkh
Forked from anonymous/index.html
Created January 29, 2016 00:23
Show Gist options
  • Save waynelkh/5e2f86c11aaa799719ab to your computer and use it in GitHub Desktop.
Save waynelkh/5e2f86c11aaa799719ab to your computer and use it in GitHub Desktop.
testing on jsbin // source http://jsbin.com/yamiyo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>testing on jsbin</title>
<script src="http://npmcdn.com/redux@3.0.6/dist/redux.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.css">
</head>
<body>
<pre><div id="app">Result</div></pre>
<div id="mocha"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/chai/1.9.0/chai.js"></script>
<script>
</script>
<script id="jsbin-javascript">
'use strict';
console.clear();
var result = document.querySelector('#app');
var show = function show(o) {
result.textContent = JSON.stringify(o);
};
var _Redux = Redux;
var createStore = _Redux.createStore;
var compose = _Redux.compose;
var reducer = function reducer(state, action) {
if (state === undefined) state = 10;
if (!action) return state;
switch (action.type) {
case 'INCREASE':
return ++state;
case 'DECREASE':
return --state;
default:
return state;
}
};
var store = createStore(reducer, 10);
function a(_x2) {
var _arguments = arguments;
var _again = true;
_function: while (_again) {
var n = _x2;
acc = undefined;
_again = false;
var acc = _arguments.length <= 1 || _arguments[1] === undefined ? 0 : _arguments[1];
if (n <= 0) return acc;
_arguments = [_x2 = n - 1, acc + n];
_again = true;
continue _function;
}
}
// prime number
function isPrime(n) {
for (var i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) return false;
}return true;
}
function PrimeList(N) {
var list = [];
for (var i = 2; i != N; ++i) {
if (isPrime(i)) list.push(i);
}
return list;
}
var Plus = function Plus(n1, n2) {
return n2 ? n1 + n2 : function (n2) {
return n1 + n2;
};
};
mocha.setup('bdd');
var expect = chai.expect;
describe('Prime number', function () {
it('can be number', function () {
expect(isPrime(10)).to.not.be.ok;
expect(isPrime(2)).to.be.ok;
expect(isPrime(5)).to.be.ok;
expect(isPrime(7)).to.be.ok;
expect(isPrime(9)).to.not.be.ok;
});
it('prime list match prime number', function () {
var expected = PrimeList(10).map(function (d) {
return isPrime(d);
}).every(function (d) {
return d === true;
});
expect(expected).to.be.ok;
});
});
describe('Recursive sum', function () {
it('1=1', function () {
expect(a(1)).to.equal(1);
});
it('2=3', function () {
expect(a(2)).to.equal(3);
});
it('3=6', function () {
expect(a(3)).to.equal(6);
});
});
describe('Store', function () {
var s = undefined;
beforeEach(function () {
s = createStore(reducer);
});
it('initial state is 10', function () {
expect(s.getState()).to.equal(10);
});
it('disptch increase action will plus', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "INCREASE" });
expect(s.getState()).to.equal(11);
});
it('disptch decrease action will minus', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "DECREASE" });
expect(s.getState()).to.equal(9);
});
it('disptch unknow action will not change any state', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "GGGGGGGG" });
s.dispatch({ type: '' });
expect(s.getState()).to.equal(10);
});
});
describe('Reducer', function () {
it('INCREASE', function () {
expect(reducer(1, { type: 'INCREASE' })).to.equal(2);
});
it('DECREASE', function () {
expect(reducer(1, { type: 'DECREASE' })).to.equal(0);
});
it('handle unknow action type', function () {
expect(reducer(1, { type: 'SOME' })).to.equal(1);
});
it('handle undefined state', function () {
expect(reducer(undefined, { type: 'SOME' })).to.equal(10);
});
it('Only one parameter', function () {
expect(reducer(0)).to.equal(0);
});
});
describe('Plus function', function () {
it('sum with two paramter', function () {
expect(Plus(1, 2)).to.equal(3);
});
it('sum with curry function', function () {
expect(Plus(1)(2)).to.equal(3);
});
});
mocha.run();
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>testing on jsbin</title>
<script src="//npmcdn.com/redux@3.0.6/dist/redux.js"><\/script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.css">
</head>
<body>
<pre><div id="app">Result</div></pre>
<div id="mocha"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.js"><\/script>
<script src="//cdnjs.cloudflare.com/ajax/libs/chai/1.9.0/chai.js"><\/script>
<script>
<\/script>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">console.clear();
let result = document.querySelector('#app');
const show = (o) => {result.textContent = JSON.stringify(o) };
const { createStore, compose } = Redux;
const reducer = (state = 10, action) => {
if(!action) return state;
switch(action.type){
case 'INCREASE':
return ++state;
case 'DECREASE':
return --state;
default:
return state;
}
};
const store = createStore(reducer,10);
function a(n,acc = 0){
if (n<=0) return acc;
return a(n-1, acc + n);
}
// prime number
function isPrime(n){
for(let i=2; i <= Math.sqrt(n);i++)
if (n%i === 0) return false;
return true
}
function PrimeList(N) {
var list = [];
for (var i = 2; i != N; ++i) {
if (isPrime(i)) list.push(i);
}
return list;
}
const Plus = (n1, n2) => n2 ? n1 + n2 : (n2) => n1 + n2;
mocha.setup('bdd');
var expect = chai.expect;
describe('Prime number', () => {
it('can be number', () => {
expect(isPrime(10)).to.not.be.ok;
expect(isPrime(2)).to.be.ok;
expect(isPrime(5)).to.be.ok;
expect(isPrime(7)).to.be.ok;
expect(isPrime(9)).to.not.be.ok;
});
it('prime list match prime number', () => {
const expected = PrimeList(10)
.map(d => isPrime(d))
.every(d=> d === true );
expect(expected).to.be.ok;
});
});
describe('Recursive sum', () => {
it('1=1', ()=> {
expect(a(1)).to.equal(1);
});
it('2=3', ()=> {
expect(a(2)).to.equal(3);
});
it('3=6', ()=> {
expect(a(3)).to.equal(6);
});
})
describe('Store', () => {
let s;
beforeEach(() => {
s = createStore(reducer);
});
it('initial state is 10', () => {
expect(s.getState()).to.equal(10);
});
it('disptch increase action will plus', () => {
expect(s.getState()).to.equal(10);
s.dispatch({type:"INCREASE"});
expect(s.getState()).to.equal(11);
});
it('disptch decrease action will minus', () => {
expect(s.getState()).to.equal(10);
s.dispatch({type:"DECREASE"});
expect(s.getState()).to.equal(9);
});
it('disptch unknow action will not change any state', () => {
expect(s.getState()).to.equal(10);
s.dispatch({type:"GGGGGGGG"});
s.dispatch({type:''});
expect(s.getState()).to.equal(10);
});
});
describe('Reducer', () => {
it('INCREASE', () => {
expect(reducer(1,{type:'INCREASE'})).to.equal(2);
});
it('DECREASE', () => {
expect(reducer(1,{type:'DECREASE'})).to.equal(0);
});
it('handle unknow action type', () => {
expect(reducer(1,{type:'SOME'})).to.equal(1);
});
it('handle undefined state', () => {
expect(reducer(undefined,{type:'SOME'})).to.equal(10);
});
it('Only one parameter', () => {
expect(reducer(0)).to.equal(0);
});
});
describe('Plus function', () => {
it('sum with two paramter', () => {
expect(Plus(1,2)).to.equal(3);
});
it('sum with curry function', () => {
expect(Plus(1)(2)).to.equal(3);
});
});
mocha.run();
</script></body>
</html>
'use strict';
console.clear();
var result = document.querySelector('#app');
var show = function show(o) {
result.textContent = JSON.stringify(o);
};
var _Redux = Redux;
var createStore = _Redux.createStore;
var compose = _Redux.compose;
var reducer = function reducer(state, action) {
if (state === undefined) state = 10;
if (!action) return state;
switch (action.type) {
case 'INCREASE':
return ++state;
case 'DECREASE':
return --state;
default:
return state;
}
};
var store = createStore(reducer, 10);
function a(_x2) {
var _arguments = arguments;
var _again = true;
_function: while (_again) {
var n = _x2;
acc = undefined;
_again = false;
var acc = _arguments.length <= 1 || _arguments[1] === undefined ? 0 : _arguments[1];
if (n <= 0) return acc;
_arguments = [_x2 = n - 1, acc + n];
_again = true;
continue _function;
}
}
// prime number
function isPrime(n) {
for (var i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) return false;
}return true;
}
function PrimeList(N) {
var list = [];
for (var i = 2; i != N; ++i) {
if (isPrime(i)) list.push(i);
}
return list;
}
var Plus = function Plus(n1, n2) {
return n2 ? n1 + n2 : function (n2) {
return n1 + n2;
};
};
mocha.setup('bdd');
var expect = chai.expect;
describe('Prime number', function () {
it('can be number', function () {
expect(isPrime(10)).to.not.be.ok;
expect(isPrime(2)).to.be.ok;
expect(isPrime(5)).to.be.ok;
expect(isPrime(7)).to.be.ok;
expect(isPrime(9)).to.not.be.ok;
});
it('prime list match prime number', function () {
var expected = PrimeList(10).map(function (d) {
return isPrime(d);
}).every(function (d) {
return d === true;
});
expect(expected).to.be.ok;
});
});
describe('Recursive sum', function () {
it('1=1', function () {
expect(a(1)).to.equal(1);
});
it('2=3', function () {
expect(a(2)).to.equal(3);
});
it('3=6', function () {
expect(a(3)).to.equal(6);
});
});
describe('Store', function () {
var s = undefined;
beforeEach(function () {
s = createStore(reducer);
});
it('initial state is 10', function () {
expect(s.getState()).to.equal(10);
});
it('disptch increase action will plus', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "INCREASE" });
expect(s.getState()).to.equal(11);
});
it('disptch decrease action will minus', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "DECREASE" });
expect(s.getState()).to.equal(9);
});
it('disptch unknow action will not change any state', function () {
expect(s.getState()).to.equal(10);
s.dispatch({ type: "GGGGGGGG" });
s.dispatch({ type: '' });
expect(s.getState()).to.equal(10);
});
});
describe('Reducer', function () {
it('INCREASE', function () {
expect(reducer(1, { type: 'INCREASE' })).to.equal(2);
});
it('DECREASE', function () {
expect(reducer(1, { type: 'DECREASE' })).to.equal(0);
});
it('handle unknow action type', function () {
expect(reducer(1, { type: 'SOME' })).to.equal(1);
});
it('handle undefined state', function () {
expect(reducer(undefined, { type: 'SOME' })).to.equal(10);
});
it('Only one parameter', function () {
expect(reducer(0)).to.equal(0);
});
});
describe('Plus function', function () {
it('sum with two paramter', function () {
expect(Plus(1, 2)).to.equal(3);
});
it('sum with curry function', function () {
expect(Plus(1)(2)).to.equal(3);
});
});
mocha.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment