Skip to content

Commit 3fd504f

Browse files
committed
added dependencies test for #17
1 parent b1ba63a commit 3fd504f

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

functions/dependencies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function isDependant(nodeChild, nodeParent, isHeadOf) {
44
const [amt, dir] = isHeadOf[nodeParent.type][nodeChild.type].split(':');
55
switch(amt){
66
case 'SING':
7-
return nodeParent.children.map(e => e.type).includes(nodeChild.type)
7+
return !nodeParent.children.map(e => e.type).includes(nodeChild.type)
88
case 'MULT':
99
switch(dir){
1010
case 'LEFT':

functions/tests/dependencies.test.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const expect = require('chai').expect
2+
3+
describe('Test Dependencies', () => {
4+
before(() => {
5+
this.isDependant = require('../dependencies.js').isDependant;
6+
this.isHeadOf = {
7+
"PARENT": {
8+
"CHILD_SING": "SING:",
9+
"CHILD_MULT": "MULT:",
10+
"CHILD_MULT_UNID": "MULT:UNID",
11+
"CHILD_MULT_LEFT": "MULT:LEFT",
12+
"CHILD_MULT_RIGHT": "MULT:RIGHT"
13+
}
14+
}
15+
})
16+
17+
it('Should only get one dependant if SING', () => {
18+
const child = {type: 'CHILD_SING', position: 0, children: []}
19+
const parent = {type: 'PARENT', position: 1, children: []}
20+
21+
expect(this.isDependant(child, parent, this.isHeadOf)).true
22+
23+
//add a children with the same name
24+
parent.children.push({type: 'CHILD_SING', position: 2})
25+
26+
expect(this.isDependant(child, parent, this.isHeadOf)).false
27+
})
28+
29+
it('Should get many dependants if MULT', () => {
30+
const child = {type: 'CHILD_MULT', position: 0, children: []}
31+
const parent = {type: 'PARENT', position: 1, children: []}
32+
33+
expect(this.isDependant(child, parent, this.isHeadOf)).true
34+
35+
//add a children with the same name
36+
parent.children.push({type: 'CHILD_MULT', position: 2})
37+
38+
expect(this.isDependant(child, parent, this.isHeadOf)).true
39+
})
40+
41+
it('Should only get dependants on one side if MULT:UNID', () => {
42+
const child = {type: 'CHILD_MULT_UNID', position: 0, children: []}
43+
const parent = {type: 'PARENT', position: 2, children: []}
44+
45+
expect(this.isDependant(child, parent, this.isHeadOf)).true
46+
47+
//add a children with the same name on the same direction
48+
parent.children.push({type: 'CHILD_MULT_UNID', position: 1})
49+
50+
expect(this.isDependant(child, parent, this.isHeadOf)).true
51+
52+
//clear children
53+
parent.children.length = 0
54+
//add a children with the same name on a different direction
55+
parent.children.push({type: 'CHILD_MULT_UNID', position: 3})
56+
57+
expect(this.isDependant(child, parent, this.isHeadOf)).false
58+
})
59+
60+
it('Should only get dependants on the left if MULT:RIGHT (because RIGHT refers to the position of the HEAD)', () => {
61+
const child = {type: 'CHILD_MULT_RIGHT', position: 0, children: []}
62+
const parent = {type: 'PARENT', position: 2, children: []}
63+
64+
expect(this.isDependant(child, parent, this.isHeadOf)).true
65+
66+
//add a children with the same name to the left
67+
parent.children.push({type: 'CHILD_MULT_RIGHT', position: 1})
68+
69+
expect(this.isDependant(child, parent, this.isHeadOf)).true
70+
71+
//change child position to the right
72+
child.position = 3
73+
expect(this.isDependant(child, parent, this.isHeadOf)).false
74+
})
75+
76+
it('Should only get dependants on the left if MULT:LEFT (because RIGHT refers to the position of the HEAD)', () => {
77+
const child = {type: 'CHILD_MULT_LEFT', position: 2, children: []}
78+
const parent = {type: 'PARENT', position: 1, children: []}
79+
80+
expect(this.isDependant(child, parent, this.isHeadOf)).true
81+
82+
//add a children with the same name to the right
83+
parent.children.push({type: 'CHILD_LEFT', position: 3})
84+
85+
expect(this.isDependant(child, parent, this.isHeadOf)).true
86+
87+
//change child position to the left
88+
child.position = 0
89+
expect(this.isDependant(child, parent, this.isHeadOf)).false
90+
})
91+
})

functions/tests/methods.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const expect = require('chai').expect
22

3-
describe('Testing Prepare Sentence', async () => {
3+
describe('Testing Prepare Sentence', () => {
44
before(() => {
55
this.prepareSentence = require('../methods.js').prepareSentence;
66

functions/tests/prepares.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Testing prepare NOUN methods', () => {
5858
})
5959
})
6060

61-
describe('Testing prepare SUBJ methods', async () => {
61+
describe('Testing prepare SUBJ methods', () => {
6262
before(() => {
6363
const { getDbRef } = require('../getter.js')
6464
this.langRef = getDbRef().database().ref('es')

0 commit comments

Comments
 (0)