1
+ import { FaceMatcher } from '../../../src/globalApi/FaceMatcher' ;
2
+ import { LabeledFaceDescriptors } from '../../../src' ;
3
+
4
+ describe ( 'globalApi' , ( ) => {
5
+
6
+ describe ( 'FaceMatcher' , ( ) => {
7
+
8
+ const json = '{"_distanceThreshold":123.321,"_labeledDescriptors":[{"_label":"foo","_descriptors":[{"0":1,"1":2,"2":3},{"0":4,"1":5,"2":6}]},{"_label":"bar","_descriptors":[{"0":7,"1":8,"2":9},{"0":3,"1":2,"2":1}]}]}' ;
9
+ const dt = 123.321 ;
10
+ const l1 = 'foo' ;
11
+ const l2 = 'bar' ;
12
+ const f1 = new Float32Array ( [ 1 , 2 , 3 ] ) ;
13
+ const f2 = new Float32Array ( [ 4 , 5 , 6 ] ) ;
14
+ const f3 = new Float32Array ( [ 7 , 8 , 9 ] ) ;
15
+ const f4 = new Float32Array ( [ 3 , 2 , 1 ] ) ;
16
+ const lds = [
17
+ new LabeledFaceDescriptors ( l1 , [ f1 , f2 ] ) ,
18
+ new LabeledFaceDescriptors ( l2 , [ f3 , f4 ] )
19
+ ] ;
20
+
21
+ it ( 'toJSON()' , ( ) => {
22
+ const fm = new FaceMatcher ( lds , dt ) ;
23
+
24
+ expect ( FaceMatcher . toJSON ( fm ) ) . toBe ( json ) ;
25
+ } ) ;
26
+
27
+ it ( 'fromJSON()' , ( ) => {
28
+ const fm = FaceMatcher . fromJSON ( json ) ;
29
+
30
+ expect ( fm . distanceThreshold ) . toBe ( dt ) ;
31
+ expect ( fm . labeledDescriptors . length ) . toBe ( 2 ) ;
32
+ expect ( fm . labeledDescriptors [ 0 ] . label ) . toBe ( l1 ) ;
33
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors . length ) . toBe ( 2 ) ;
34
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors [ 0 ] ) . toEqual ( f1 ) ;
35
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors [ 1 ] ) . toEqual ( f2 ) ;
36
+ expect ( fm . labeledDescriptors [ 1 ] . label ) . toBe ( l2 ) ;
37
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors . length ) . toBe ( 2 ) ;
38
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors [ 0 ] ) . toEqual ( f3 ) ;
39
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors [ 1 ] ) . toEqual ( f4 ) ;
40
+ } ) ;
41
+
42
+ it ( 'toJSON() => fromJSON()' , ( ) => {
43
+ const fm = FaceMatcher . fromJSON ( FaceMatcher . toJSON ( new FaceMatcher ( lds , dt ) ) ) ;
44
+
45
+ expect ( fm . distanceThreshold ) . toBe ( dt ) ;
46
+ expect ( fm . labeledDescriptors . length ) . toBe ( 2 ) ;
47
+ expect ( fm . labeledDescriptors [ 0 ] . label ) . toBe ( l1 ) ;
48
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors . length ) . toBe ( 2 ) ;
49
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors [ 0 ] ) . toEqual ( f1 ) ;
50
+ expect ( fm . labeledDescriptors [ 0 ] . descriptors [ 1 ] ) . toEqual ( f2 ) ;
51
+ expect ( fm . labeledDescriptors [ 1 ] . label ) . toBe ( l2 ) ;
52
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors . length ) . toBe ( 2 ) ;
53
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors [ 0 ] ) . toEqual ( f3 ) ;
54
+ expect ( fm . labeledDescriptors [ 1 ] . descriptors [ 1 ] ) . toEqual ( f4 ) ;
55
+ } ) ;
56
+
57
+ } ) ;
58
+
59
+ } ) ;
0 commit comments