Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"license": "MIT",
"dependencies": {
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.5.0"
"babel-preset-stage-0": "^6.5.0",
"stampit": "^3.0.6"
},
"devDependencies": {
"babel-register": "^6.14.0",
Expand Down
36 changes: 14 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
export function double ( x ) {
return x * 2;
}

export function doubleXTimes ( x, num ) {
let result = x;

for ( let i = 1; i <= num; i++ ) {
// result = result * 2;
result = double( result );
import stampit from 'stampit';
//
export const Animal = stampit({
properties: {
SOUND: "generic sound"
},
methods: {
speak(sound = this.SOUND) {
return sound;
}
}
});

return result;
}

export function doubleEach ( arr ) {
let result = arr.map( double );

// const result = arr.map( x => double( x ) );
// const result = arr.map( function ( x ) {
// return double( x );
// });
export const Reptile = stampit().compose(Animal).properties({SOUND: 'reptile sound'});

return result;
}
export const Primate = stampit().compose(Animal).properties({SOUND: 'primate sound'});

export const Human = stampit().compose(Primate).properties({SOUND: 'human sound'});
60 changes: 46 additions & 14 deletions src/spec.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,62 @@
import test from 'tape';
import { double, doubleXTimes, doubleEach } from './index';
import { Animal, Reptile, Primate, Human } from './index';
import stampit from 'stampit';
// import isStamp from 'stampit/isStamp';

test( 'double fn', function ( test ) {
const actual = double( 5 );
const expected = 10;
test('Can create "stamps?" from Animal stamp', function(test) {

test.equal( actual, expected, 'should double the value' );
const animal = Animal();

test.ok( typeof animal.speak == 'function', 'animal has a speak function.. "looks like an Animal"' );

test.equal( animal.speak(), 'generic sound', 'Sounds like an Animal');

console.log('* Animal says: ' + animal.speak() );
// Must be an Animal?

test.end();
});

test( 'doubleXTimes', function ( test ) {
const actual = doubleXTimes( 5, 3 );
const expected = 40;

test.equal( actual, expected, 'should double 5 three times' );
test('More "inheritance" stamp tests', function(test) {

let actual, expected;

const reptile = Reptile();

test.ok( typeof reptile.speak == 'function', 'reptile has a speak function.. "looks like an Animal"' );

expected = reptile.SOUND;
actual = reptile.speak();
console.log('* reptile says: ', actual);
test.equal( actual, expected, 'should make a reptile sound when it speaks.. "Sounds like a Reptile"' );

const primate = Primate();

test.ok( typeof primate.speak == 'function', 'primate has a speak function.. "looks like an Animal"' );

expected = primate.SOUND;
actual = primate.speak();
console.log('* primate says: ', actual);
test.equal( actual, expected, 'should make a primate sound when it speaks.. Sounds like a Primate' );

test.end();
});

test( 'doubleEach', function ( test ) {
const actual = doubleEach([ 0, 1, 2 ]);
const expected = [ 0, 2, 4 ];

test.deepEqual( actual, expected, 'should double each in the array' );
test('Human tests...', function(test) {

let actual, expected;

const human = Human();
//hmmmmm
test.ok( typeof human.speak == 'function', 'reptile has a speak function.. "looks like an Animal"' );

const message = 'hello';
expected = message;
actual = human.speak( message );
console.log('* human says: ', actual);
test.equal( actual, expected, 'should make a primate sound when it speaks.. Sounds like a Primate' );

test.end();
});