1
1
import { isContained , newContainedInterval } from "./interval.js" ;
2
- import { describe , expect , test } from '@jest/globals' ;
3
-
4
- describe ( 'isContained' , ( ) => {
5
- test ( 'works for a contained interval' , ( ) => {
6
- expect ( isContained ( { start :7 , end :8 , timingResult : 0 } , { start :1 , end :12 , timingResult : 0 } ) ) . toBe ( true ) ;
7
- } )
8
- test ( 'works for the same interval' , ( ) => {
9
- expect ( isContained ( { start :7 , end :8 , timingResult : 0 } , { start :7 , end :8 , timingResult : 1 } ) ) . toBe ( true ) ;
10
- } )
11
- } )
12
-
13
- describe ( 'is not contained' , ( ) => {
14
- // ---
15
- // ---
16
- test ( 'works for a left shifed interval' , ( ) => {
17
- expect ( ! isContained ( { start :7 , end :77 , timingResult : 0 } , { start :10 , end :98 , timingResult : 0 } ) ) . toBe ( true ) ;
18
- } )
19
- // ------
20
- // ---
21
- test ( 'works for a left shifed interval (bigger)' , ( ) => {
22
- expect ( ! isContained ( { start :7 , end :77 , timingResult : 0 } , { start :10 , end :70 , timingResult : 0 } ) ) . toBe ( true ) ;
23
- } )
24
- // ---
25
- // ---
26
- test ( 'works for a right shifted interval' , ( ) => {
27
- expect ( ! isContained ( { start :17 , end :87 , timingResult : 0 } , { start :10 , end :85 , timingResult : 0 } ) ) . toBe ( true ) ;
28
- } )
29
- } )
30
-
31
- describe ( 'newContainedInterval' , ( ) => {
32
- test ( 'works for an empty interval' , ( ) => {
33
- expect ( newContainedInterval ( { start :7 , end :77 , timingResult : 0 } , [ ] ) ) . toEqual ( [ { start :7 , end :77 , timingResult : 0 } ] ) ;
34
- } )
35
- test ( 'works when new interval is contained' , ( ) => {
36
- expect ( newContainedInterval ( { start :7 , end :10 , timingResult : 0 } , [ { start :5 , end :12 , timingResult : 1 } ] ) )
37
- . toEqual ( [ { start :5 , end :12 , timingResult : 1 } ] ) ;
38
- } )
39
- test ( 'works when new interval is not contained' , ( ) => {
40
- expect ( newContainedInterval ( { start :5 , end :12 , timingResult : 1 } , [ { start :7 , end :10 , timingResult : 0 } ] ) )
41
- . toEqual ( [ { start :5 , end :12 , timingResult : 1 } ] ) ;
42
- } )
43
- test ( 'works when new interval contains all exisiting' , ( ) => {
44
- expect ( newContainedInterval ( { start :5 , end :20 , timingResult : 1 } , [
45
- { start :7 , end :10 , timingResult : 1 } ,
46
- { start :12 , end :14 , timingResult : 2 } ,
47
- { start :16 , end :18 , timingResult : 3 } ,
48
- ] ) )
49
- . toEqual ( [ { start :5 , end :20 , timingResult : 1 } ] ) ;
50
- } )
51
- test ( 'works when new interval contains some exisiting' , ( ) => {
52
- let nr = newContainedInterval ( { start :5 , end :17 , timingResult : 1 } , [
53
- { start :7 , end :10 , timingResult : 1 } ,
54
- { start :12 , end :14 , timingResult : 2 } ,
55
- { start :16 , end :18 , timingResult : 3 } ,
56
- ] ) ;
57
- console . log ( "nr" , nr ) ;
58
- expect ( nr . length )
59
- . toEqual ( 2 ) ;
60
- expect ( nr )
61
- . toEqual ( [ { start :5 , end :17 , timingResult : 1 } , { start :16 , end :18 , timingResult : 3 } ] ) ;
62
- } )
63
- } )
2
+ import { describe , expect , test } from "@jest/globals" ;
3
+
4
+ describe ( "isContained Function" , ( ) => {
5
+ test ( "When the smaller interval is fully contained within the larger one, should return true" , ( ) => {
6
+ const interval1 = { start : 7 , end : 8 , timingResult : 0 } ;
7
+ const interval2 = { start : 1 , end : 12 , timingResult : 0 } ;
8
+
9
+ const result = isContained ( interval1 , interval2 ) ;
10
+
11
+ expect ( result ) . toBe ( true ) ;
12
+ } ) ;
13
+
14
+ test ( "When the smaller interval is the same as the larger one, should return true" , ( ) => {
15
+ const interval1 = { start : 7 , end : 8 , timingResult : 0 } ;
16
+ const interval2 = { start : 7 , end : 8 , timingResult : 1 } ;
17
+
18
+ const result = isContained ( interval1 , interval2 ) ;
19
+
20
+ expect ( result ) . toBe ( true ) ;
21
+ } ) ;
22
+
23
+ test ( "When the smaller interval is completely to the left, should return false" , ( ) => {
24
+ const interval1 = { start : 7 , end : 77 , timingResult : 0 } ;
25
+ const interval2 = { start : 10 , end : 98 , timingResult : 0 } ;
26
+
27
+ const result = isContained ( interval1 , interval2 ) ;
28
+
29
+ expect ( result ) . toBe ( false ) ;
30
+ } ) ;
31
+
32
+ test ( "When the smaller interval is not contained within the larger one, should return false" , ( ) => {
33
+ const interval1 = { start : 7 , end : 77 , timingResult : 0 } ;
34
+ const interval2 = { start : 10 , end : 70 , timingResult : 0 } ;
35
+
36
+ const result = isContained ( interval1 , interval2 ) ;
37
+
38
+ expect ( result ) . toBe ( false ) ;
39
+ } ) ;
40
+
41
+ test ( "When the larger interval is completely to the right, should return false" , ( ) => {
42
+ const interval1 = { start : 17 , end : 87 , timingResult : 0 } ;
43
+ const interval2 = { start : 10 , end : 85 , timingResult : 0 } ;
44
+
45
+ const result = isContained ( interval1 , interval2 ) ;
46
+
47
+ expect ( result ) . toBe ( false ) ;
48
+ } ) ;
49
+ } ) ;
50
+
51
+ describe ( "newContainedInterval Function" , ( ) => {
52
+ test ( "When new interval is empty, should return an array with the same interval" , ( ) => {
53
+ const existingInterval = { start : 7 , end : 77 , timingResult : 0 } ;
54
+ const newIntervals = [ ] ;
55
+
56
+ const result = newContainedInterval ( existingInterval , newIntervals ) ;
57
+
58
+ expect ( result ) . toEqual ( [ existingInterval ] ) ;
59
+ } ) ;
60
+
61
+ test ( "When new interval is contained, should return an array with the new interval" , ( ) => {
62
+ const existingInterval = { start : 7 , end : 10 , timingResult : 0 } ;
63
+ const newIntervals = [ { start : 5 , end : 12 , timingResult : 1 } ] ;
64
+
65
+ const result = newContainedInterval ( existingInterval , newIntervals ) ;
66
+
67
+ expect ( result ) . toEqual ( newIntervals ) ;
68
+ } ) ;
69
+
70
+ test ( "When new interval is not contained, should return an array with the existing interval" , ( ) => {
71
+ const existingInterval = { start : 5 , end : 12 , timingResult : 1 } ;
72
+ const newIntervals = [ { start : 7 , end : 10 , timingResult : 0 } ] ;
73
+
74
+ const result = newContainedInterval ( existingInterval , newIntervals ) ;
75
+
76
+ expect ( result ) . toEqual ( [ existingInterval ] ) ;
77
+ } ) ;
78
+
79
+ test ( "When new interval contains all existing, should return an array with the new interval" , ( ) => {
80
+ const newInterval = { start : 5 , end : 20 , timingResult : 1 } ;
81
+ const existingIntervals = [
82
+ { start : 7 , end : 10 , timingResult : 1 } ,
83
+ { start : 12 , end : 14 , timingResult : 2 } ,
84
+ { start : 16 , end : 18 , timingResult : 3 } ,
85
+ ] ;
86
+
87
+ const result = newContainedInterval ( newInterval , existingIntervals ) ;
88
+
89
+ expect ( result ) . toEqual ( [ newInterval ] ) ;
90
+ } ) ;
91
+
92
+ test ( "When new interval contains some existing, should return an array with the new and some existing intervals" , ( ) => {
93
+ const newInterval = { start : 5 , end : 17 , timingResult : 1 } ;
94
+ const existingIntervals = [
95
+ { start : 7 , end : 10 , timingResult : 1 } ,
96
+ { start : 12 , end : 14 , timingResult : 2 } ,
97
+ { start : 16 , end : 18 , timingResult : 3 } ,
98
+ ] ;
99
+
100
+ const result = newContainedInterval ( newInterval , existingIntervals ) ;
101
+
102
+ expect ( result ) . toEqual ( [
103
+ { start : 5 , end : 17 , timingResult : 1 } ,
104
+ { start : 16 , end : 18 , timingResult : 3 } ,
105
+ ] ) ;
106
+ } ) ;
107
+ } ) ;
0 commit comments