@@ -4,7 +4,7 @@ const expect = require('chai').expect
4
4
/////// MAIN METHODS ///////
5
5
////////////////////////////
6
6
7
- describe ( 'Testing Prepare Sentence ' , ( ) => {
7
+ describe ( 'Testing prepareSentence ' , ( ) => {
8
8
before ( ( ) => {
9
9
this . prepareSentence = require ( '../methods.js' ) . prepareSentence ;
10
10
@@ -51,6 +51,231 @@ describe('Testing Prepare Sentence', () => {
51
51
} )
52
52
} )
53
53
54
+ describe ( 'Testing parseDependencies' , ( ) => {
55
+ before ( ( ) => {
56
+ this . parseDependencies = require ( '../methods.js' ) . parseDependencies ;
57
+
58
+ const testObj = [
59
+ {
60
+ words : [ ] ,
61
+ types : [ ] ,
62
+ composed : true ,
63
+ position : 0 ,
64
+ type : 'SUBJ' ,
65
+ children : [ ] ,
66
+ meta : { } ,
67
+ props : { } ,
68
+ headless : true
69
+ } ,
70
+ {
71
+ words : [ ] ,
72
+ types : [ ] ,
73
+ composed : true ,
74
+ position : 1 ,
75
+ type : 'ADJ' ,
76
+ children : [ ] ,
77
+ meta : { } ,
78
+ props : { } ,
79
+ headless : true
80
+ } ,
81
+ {
82
+ words : [ ] ,
83
+ types : [ ] ,
84
+ composed : true ,
85
+ position : 2 ,
86
+ type : 'VERB' ,
87
+ children : [ ] ,
88
+ meta : { } ,
89
+ props : { } ,
90
+ headless : true
91
+ } ,
92
+ {
93
+ words : [ ] ,
94
+ types : [ ] ,
95
+ composed : true ,
96
+ position : 3 ,
97
+ type : 'ADV' ,
98
+ children : [ ] ,
99
+ meta : { } ,
100
+ props : { } ,
101
+ headless : true
102
+ }
103
+ ]
104
+
105
+ this . resultObj = this . parseDependencies ( testObj , [ ] , 'es' )
106
+ } )
107
+
108
+ it ( 'headless should be false in elements that are children of others' , async ( ) => {
109
+ const thisResult = await this . resultObj ;
110
+ const thisResultDependencies = thisResult [ 0 ]
111
+ const childrenList = thisResultDependencies . map ( e => e . children . map ( c => c . position ) ) . flat ( )
112
+ for ( elem of thisResultDependencies ) {
113
+ if ( ! elem . headless ) {
114
+ expect ( childrenList ) . to . include ( elem . position )
115
+ }
116
+ }
117
+ } )
118
+
119
+ it ( 'headless should be true in elements that are not children of others' , async ( ) => {
120
+ const thisResult = await this . resultObj ;
121
+ const thisResultDependencies = thisResult [ 0 ]
122
+ const thisResultHeadless = thisResult [ 1 ]
123
+ const childrenList = thisResultDependencies . map ( e => e . children . map ( c => c . position ) ) . flat ( )
124
+ for ( elem of thisResultDependencies ) {
125
+ if ( elem . headless ) {
126
+ expect ( childrenList ) . not . to . include ( elem . position )
127
+ expect ( thisResultHeadless . map ( c => c . position ) ) . to . include ( elem . position )
128
+ }
129
+ }
130
+ } )
131
+ } )
132
+
133
+ describe ( 'Testing handleSentence' , ( ) => {
134
+ before ( ( ) => {
135
+ this . handleSentence = require ( '../methods.js' ) . handleSentence ;
136
+
137
+ const testObj = [
138
+ {
139
+ words : [ 'mamá' ] ,
140
+ types : [ 'SUBJ' ] ,
141
+ composed : true ,
142
+ position : 0 ,
143
+ type : 'SUBJ' ,
144
+ children : [
145
+ { position : 1 , type : 'ADJ' }
146
+ ] ,
147
+ meta : { PERSON : 'ella' } ,
148
+ props : { } ,
149
+ headless : true
150
+ } ,
151
+ {
152
+ words : [ 'preparado' ] ,
153
+ types : [ 'ADJ' ] ,
154
+ composed : true ,
155
+ position : 1 ,
156
+ type : 'ADJ' ,
157
+ children : [ ] ,
158
+ meta : { } ,
159
+ props : { } ,
160
+ headless : true
161
+ } ,
162
+ {
163
+ words : [ 'comer' ] ,
164
+ types : [ 'VERB' ] ,
165
+ composed : true ,
166
+ position : 2 ,
167
+ type : 'VERB' ,
168
+ children : [
169
+ { position : 0 , type : 'SUBJ' } ,
170
+ { position : 3 , type : 'ADV' }
171
+ ] ,
172
+ meta : { } ,
173
+ props : { } ,
174
+ headless : true
175
+ } ,
176
+ {
177
+ words : [ 'mañana' ] ,
178
+ types : [ 'ADV' ] ,
179
+ composed : true ,
180
+ position : 3 ,
181
+ type : 'ADV' ,
182
+ children : [ ] ,
183
+ meta : { TIME : 'futuro' } ,
184
+ props : { } ,
185
+ headless : true
186
+ }
187
+ ]
188
+
189
+ this . resultObj = this . handleSentence ( testObj , 'es' , { } , 'static' )
190
+ } )
191
+
192
+ it ( 'VERB should get meta TIME from ADV' , async ( ) => {
193
+ const thisResult = await this . resultObj ;
194
+ const verbIndex = thisResult . findIndex ( e => e . type === 'VERB' )
195
+ const advIndex = thisResult . findIndex ( e => e . type === 'ADV' )
196
+ expect ( thisResult [ verbIndex ] . meta . TIME ) . to . equal ( thisResult [ advIndex ] . meta . TIME )
197
+ } )
198
+
199
+ it ( 'VERB should get meta PERSON from SUBJ' , async ( ) => {
200
+ const thisResult = await this . resultObj ;
201
+ const verbIndex = thisResult . findIndex ( e => e . type === 'VERB' )
202
+ const subjIndex = thisResult . findIndex ( e => e . type === 'SUBJ' )
203
+ expect ( thisResult [ verbIndex ] . meta . PERSON ) . to . equal ( thisResult [ subjIndex ] . meta . PERSON )
204
+ } )
205
+
206
+ it ( 'ADJ should inherit meta PERSON from SUBJ' , async ( ) => {
207
+ const thisResult = await this . resultObj ;
208
+ const adjIndex = thisResult . findIndex ( e => e . type === 'ADJ' )
209
+ const subjIndex = thisResult . findIndex ( e => e . type === 'SUBJ' )
210
+ expect ( thisResult [ adjIndex ] . meta . TIME ) . to . equal ( thisResult [ subjIndex ] . meta . TIME )
211
+ } )
212
+ } )
213
+
214
+ describe ( 'Testing realiseSentence' , ( ) => {
215
+ before ( ( ) => {
216
+ this . realiseSentence = require ( '../methods.js' ) . realiseSentence ;
217
+
218
+ const testObj = [
219
+ {
220
+ words : [ ] ,
221
+ types : [ ] ,
222
+ composed : true ,
223
+ position : 0 ,
224
+ type : 'SUBJ' ,
225
+ children : [ { position : 1 , type : 'ADJ' } ] ,
226
+ meta : { PERSON : 'test' } ,
227
+ props : { } ,
228
+ headless : true
229
+ } ,
230
+ {
231
+ words : [ ] ,
232
+ types : [ ] ,
233
+ composed : true ,
234
+ position : 1 ,
235
+ type : 'ADJ' ,
236
+ children : [ ] ,
237
+ meta : { } ,
238
+ props : { } ,
239
+ headless : true
240
+ } ,
241
+ {
242
+ words : [ ] ,
243
+ types : [ ] ,
244
+ composed : true ,
245
+ position : 2 ,
246
+ type : 'SUBJ' ,
247
+ children : [ { position : 1 , type : 'ADJ' } ] ,
248
+ meta : { } ,
249
+ props : { } ,
250
+ headless : true
251
+ } ,
252
+ {
253
+ words : [ ] ,
254
+ types : [ ] ,
255
+ composed : true ,
256
+ position : 3 ,
257
+ type : 'ADJ' ,
258
+ children : [ ] ,
259
+ meta : { TIME : 'test' } ,
260
+ props : { } ,
261
+ headless : true
262
+ }
263
+ ]
264
+
265
+ this . resultObj = this . realiseSentence ( testObj , 'es' )
266
+ } )
267
+
268
+ it ( 'Should generate a string' , async ( ) => {
269
+ const thisResult = await this . resultObj ;
270
+ expect ( typeof ( thisResult ) ) . to . equal ( 'string' )
271
+ } )
272
+
273
+ it ( 'Should add a connector between two equal similar heads' , async ( ) => {
274
+ const thisResult = await this . resultObj ;
275
+ expect ( thisResult ) . to . equal ( 'y' )
276
+ } )
277
+ } )
278
+
54
279
////////////////////////////
55
280
/////// PREPARES ///////
56
281
////////////////////////////
0 commit comments