-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add state functions with tests (WIP)
- Loading branch information
1 parent
fdcd119
commit f58d4a0
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { State } from "../utils/state"; | ||
|
||
|
||
// Using this function because literal comparison between 2 types (state1 == state2) always return false | ||
// TODO: melhorar formato de verificação | ||
function areEqual(state1: State, state2: State){ | ||
const equal = true; | ||
for (let l in state1){ | ||
for (let c in state1){ | ||
if(!(state1[l][c] == state2[l][c])){ | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
// TODO: melhorar formato de verificação | ||
function includes(state: State, list: State[]){ | ||
for (let s of list){ | ||
if(areEqual(s, state)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function readState(state: State){ | ||
console.log('---------'); | ||
for(let l of state){ | ||
console.log(l); | ||
} | ||
console.log('---------'); | ||
} | ||
|
||
export { areEqual, includes, readState } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { expect } from 'chai'; | ||
import { areEqual, includes } from '../src/functions/state'; | ||
import { State } from '../src/utils/state'; | ||
|
||
describe('State Smoke Tests', () => { | ||
it('Should exist areEqual function', () => { | ||
expect(areEqual).to.exist; | ||
}); | ||
|
||
it('Should return boolean when call areEqual function', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
expect(areEqual(state1, state2)).to.be.a('Boolean'); | ||
}); | ||
|
||
it('Should exist includes function', () => { | ||
expect(includes).to.exist; | ||
}); | ||
|
||
it('Should return boolean when call includes function', () => { | ||
const state: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const list: State[] = [state]; | ||
expect(includes(state, list)).to.be.a('Boolean'); | ||
}); | ||
}); | ||
|
||
describe('Testing returns of areEqual function', () => { | ||
it('Should return true', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
expect(areEqual(state1, state2)).to.eql(true); | ||
}); | ||
|
||
it('Should return false', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, null, 8]]; | ||
expect(areEqual(state1, state2)).to.eql(false); | ||
}); | ||
|
||
it('Should return true', () => { | ||
const state1: State = [[4,5,3], [2,1,6], [7, null, 8]]; | ||
const state2: State = [[4,5,3], [2,1,6], [7, null, 8]]; | ||
expect(areEqual(state1, state2)).to.eql(true); | ||
}); | ||
|
||
it('Should return false', () => { | ||
const state1: State = [[4,5,3], [null,5,6], [2, 7, 8]]; | ||
const state2: State = [[4,1,3], [2,1,6], [7, 7, 8]]; | ||
expect(areEqual(state1, state2)).to.eql(false); | ||
}); | ||
}); | ||
|
||
|
||
describe('Testing returns of includes function', () => { | ||
it('Should return true', () => { | ||
const state: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const list: State[] = [state]; | ||
expect(includes(state, list)).to.eql(true); | ||
}); | ||
|
||
it('Should return false', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, null, 8]]; | ||
const list: State[] = [state1]; | ||
expect(includes(state2, list)).to.eql(false); | ||
}); | ||
|
||
it('Should return true', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, null, 8]]; | ||
const list: State[] = []; | ||
list.push(state1); | ||
list.push(state2); | ||
expect(includes(state2, list)).to.eql(true); | ||
}); | ||
|
||
it('Should return false', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state2: State = [[1,2,3], [4,5,6], [7, null, 8]]; | ||
const state3: State = [[1,2,5], [3,4,6], [7, null, 8]]; | ||
const list: State[] = []; | ||
list.push(state1); | ||
list.push(state2); | ||
expect(includes(state3, list)).to.eql(false); | ||
}); | ||
|
||
it('Should return false', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const list: State[] = []; | ||
expect(includes(state1, list)).to.eql(false); | ||
}); | ||
|
||
it('Should return true', () => { | ||
const state1: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const state1Copy: State = [[1,2,3], [4,5,6], [7, 8, null]]; | ||
const list: State[] = []; | ||
list.push(state1); | ||
expect(includes(state1Copy, list)).to.eql(true); | ||
}); | ||
}); |