@@ -1021,153 +1021,163 @@ describe('When calculating minimum ticks and minimum tick values', () => {
10211021describe ( 'When rounding a value to the nearest tick value' , ( ) => {
10221022 describe ( 'For unit code "2" and with a tickIncrement of 2 (e.g. corn)' , ( ) => {
10231023 let uc ;
1024+ let mt ;
10241025
10251026 beforeEach ( ( ) => {
10261027 uc = UnitCode . parse ( '2' ) ;
1028+ mt = uc . getMinimumTick ( 2 ) ;
10271029 } ) ;
10281030
10291031 it ( 'A value of 0 should be rounded to 0' , ( ) => {
1030- expect ( uc . roundToNearestTick ( 0 , 2 ) ) . toEqual ( 0 ) ;
1032+ expect ( uc . roundToNearestTick ( 0 , mt ) ) . toEqual ( 0 ) ;
10311033 } ) ;
10321034
10331035 it ( 'A value of 488.5 should be rounded to 488.5' , ( ) => {
1034- expect ( uc . roundToNearestTick ( 488.5 , 2 ) ) . toEqual ( 488.5 ) ;
1036+ expect ( uc . roundToNearestTick ( 488.5 , mt ) ) . toEqual ( 488.5 ) ;
10351037 } ) ;
10361038
10371039 it ( 'A value of 488.51 should be rounded to 488.5' , ( ) => {
1038- expect ( uc . roundToNearestTick ( 488.51 , 2 ) ) . toEqual ( 488.5 ) ;
1040+ expect ( uc . roundToNearestTick ( 488.51 , mt ) ) . toEqual ( 488.5 ) ;
10391041 } ) ;
10401042
10411043 it ( 'A value of 488.74 should be rounded to 488.75' , ( ) => {
1042- expect ( uc . roundToNearestTick ( 488.74 , 2 ) ) . toEqual ( 488.75 ) ;
1044+ expect ( uc . roundToNearestTick ( 488.74 , mt ) ) . toEqual ( 488.75 ) ;
10431045 } ) ;
10441046
10451047 it ( 'A value of 488.625 should be rounded to 488.75' , ( ) => {
1046- expect ( uc . roundToNearestTick ( 488.625 , 2 ) ) . toEqual ( 488.75 ) ;
1048+ expect ( uc . roundToNearestTick ( 488.625 , mt ) ) . toEqual ( 488.75 ) ;
10471049 } ) ;
10481050
10491051 it ( 'A value of 488.625 should be rounded to 488.5 (when using "roundDown" option)' , ( ) => {
1050- expect ( uc . roundToNearestTick ( 488.625 , 2 , true ) ) . toEqual ( 488.5 ) ;
1052+ expect ( uc . roundToNearestTick ( 488.625 , mt , true ) ) . toEqual ( 488.5 ) ;
10511053 } ) ;
10521054 } ) ;
10531055
10541056 describe ( 'For unit code "A" and with a tickIncrement of 25 (e.g. e-mini)' , ( ) => {
10551057 let uc ;
1058+ let mt ;
10561059
10571060 beforeEach ( ( ) => {
10581061 uc = UnitCode . parse ( 'A' ) ;
1062+ mt = uc . getMinimumTick ( 25 ) ;
10591063 } ) ;
10601064
10611065 it ( 'A value of 4455.5 should be rounded to 4455.5' , ( ) => {
1062- expect ( uc . roundToNearestTick ( 4455.5 , 25 ) ) . toEqual ( 4455.5 ) ;
1066+ expect ( uc . roundToNearestTick ( 4455.5 , mt ) ) . toEqual ( 4455.5 ) ;
10631067 } ) ;
10641068
10651069 it ( 'A value of 4455.51 should be rounded to 4455.5' , ( ) => {
1066- expect ( uc . roundToNearestTick ( 4455.51 , 25 ) ) . toEqual ( 4455.5 ) ;
1070+ expect ( uc . roundToNearestTick ( 4455.51 , mt ) ) . toEqual ( 4455.5 ) ;
10671071 } ) ;
10681072
10691073 it ( 'A value of 4455.74 should be rounded to 4455.75' , ( ) => {
1070- expect ( uc . roundToNearestTick ( 4455.74 , 25 ) ) . toEqual ( 4455.75 ) ;
1074+ expect ( uc . roundToNearestTick ( 4455.74 , mt ) ) . toEqual ( 4455.75 ) ;
10711075 } ) ;
10721076
10731077 it ( 'A value of 4455.625 should be rounded to 4455.75' , ( ) => {
1074- expect ( uc . roundToNearestTick ( 4455.625 , 25 ) ) . toEqual ( 4455.75 ) ;
1078+ expect ( uc . roundToNearestTick ( 4455.625 , mt ) ) . toEqual ( 4455.75 ) ;
10751079 } ) ;
10761080
10771081 it ( 'A value of 4455.625 should be rounded to 4455.5 (when using "roundDown" option)' , ( ) => {
1078- expect ( uc . roundToNearestTick ( 4455.625 , 25 , true ) ) . toEqual ( 4455.5 ) ;
1082+ expect ( uc . roundToNearestTick ( 4455.625 , mt , true ) ) . toEqual ( 4455.5 ) ;
10791083 } ) ;
10801084 } ) ;
10811085
10821086 describe ( 'For unit code "A" and with a tickIncrement of 1 (e.g. crude)' , ( ) => {
10831087 let uc ;
1088+ let mt ;
10841089
10851090 beforeEach ( ( ) => {
10861091 uc = UnitCode . parse ( 'A' ) ;
1092+ mt = uc . getMinimumTick ( 1 ) ;
10871093 } ) ;
10881094
10891095 it ( 'A value of 87.30 should be rounded to 87.30' , ( ) => {
1090- expect ( uc . roundToNearestTick ( 87.30 , 1 ) ) . toEqual ( 87.30 ) ;
1096+ expect ( uc . roundToNearestTick ( 87.30 , mt ) ) . toEqual ( 87.30 ) ;
10911097 } ) ;
10921098
10931099 it ( 'A value of 87.31 should be rounded to 87.31' , ( ) => {
1094- expect ( uc . roundToNearestTick ( 87.31 , 1 ) ) . toEqual ( 87.31 ) ;
1100+ expect ( uc . roundToNearestTick ( 87.31 , mt ) ) . toEqual ( 87.31 ) ;
10951101 } ) ;
10961102
10971103 it ( 'A value of 87.312 should be rounded to 87.31' , ( ) => {
1098- expect ( uc . roundToNearestTick ( 87.312 , 1 ) ) . toEqual ( 87.31 ) ;
1104+ expect ( uc . roundToNearestTick ( 87.312 , mt ) ) . toEqual ( 87.31 ) ;
10991105 } ) ;
11001106
11011107 it ( 'A value of 87.318 should be rounded to 87.32' , ( ) => {
1102- expect ( uc . roundToNearestTick ( 87.318 , 1 ) ) . toEqual ( 87.32 ) ;
1108+ expect ( uc . roundToNearestTick ( 87.318 , mt ) ) . toEqual ( 87.32 ) ;
11031109 } ) ;
11041110
11051111 it ( 'A value of 87.325 should be rounded to 87.33' , ( ) => {
1106- expect ( uc . roundToNearestTick ( 87.325 , 1 ) ) . toEqual ( 87.33 ) ;
1112+ expect ( uc . roundToNearestTick ( 87.325 , mt ) ) . toEqual ( 87.33 ) ;
11071113 } ) ;
11081114
11091115 it ( 'A value of 87.325 should be rounded to 87.32 (when using "roundDown" option)' , ( ) => {
1110- expect ( uc . roundToNearestTick ( 87.325 , 1 , true ) ) . toEqual ( 87.32 ) ;
1116+ expect ( uc . roundToNearestTick ( 87.325 , mt , true ) ) . toEqual ( 87.32 ) ;
11111117 } ) ;
11121118 } ) ;
11131119
11141120 describe ( 'For unit code "9" and with a tickIncrement of 1 (e.g. gold)' , ( ) => {
11151121 let uc ;
1122+ let mt ;
11161123
11171124 beforeEach ( ( ) => {
11181125 uc = UnitCode . parse ( '9' ) ;
1126+ mt = uc . getMinimumTick ( 1 ) ;
11191127 } ) ;
11201128
11211129 it ( 'A value of 1922.5 should be rounded to 1922.5' , ( ) => {
1122- expect ( uc . roundToNearestTick ( 1922.5 , 1 ) ) . toEqual ( 1922.5 ) ;
1130+ expect ( uc . roundToNearestTick ( 1922.5 , mt ) ) . toEqual ( 1922.5 ) ;
11231131 } ) ;
11241132
11251133 it ( 'A value of 1922.6 should be rounded to 1922.6' , ( ) => {
1126- expect ( uc . roundToNearestTick ( 1922.6 , 1 ) ) . toEqual ( 1922.6 ) ;
1134+ expect ( uc . roundToNearestTick ( 1922.6 , mt ) ) . toEqual ( 1922.6 ) ;
11271135 } ) ;
11281136
11291137 it ( 'A value of 1922.51 should be rounded to 1922.5' , ( ) => {
1130- expect ( uc . roundToNearestTick ( 1922.51 , 1 ) ) . toEqual ( 1922.5 ) ;
1138+ expect ( uc . roundToNearestTick ( 1922.51 , mt ) ) . toEqual ( 1922.5 ) ;
11311139 } ) ;
11321140
11331141 it ( 'A value of 1922.59 should be rounded to 1922.6' , ( ) => {
1134- expect ( uc . roundToNearestTick ( 1922.59 , 1 ) ) . toEqual ( 1922.6 ) ;
1142+ expect ( uc . roundToNearestTick ( 1922.59 , mt ) ) . toEqual ( 1922.6 ) ;
11351143 } ) ;
11361144
11371145 it ( 'A value of 1922.55 should be rounded to 1922.6' , ( ) => {
1138- expect ( uc . roundToNearestTick ( 1922.55 , 1 ) ) . toEqual ( 1922.6 ) ;
1146+ expect ( uc . roundToNearestTick ( 1922.55 , mt ) ) . toEqual ( 1922.6 ) ;
11391147 } ) ;
11401148
11411149 it ( 'A value of 1922.55 should be rounded to 1922.5 (when using "roundDown" option)' , ( ) => {
1142- expect ( uc . roundToNearestTick ( 1922.55 , 1 , true ) ) . toEqual ( 1922.5 ) ;
1150+ expect ( uc . roundToNearestTick ( 1922.55 , mt , true ) ) . toEqual ( 1922.5 ) ;
11431151 } ) ;
11441152 } ) ;
11451153
11461154 describe ( 'For unit code "5" and with a tickIncrement of 1 (e.g. t-notes)' , ( ) => {
11471155 let uc ;
1156+ let mt ;
11481157
11491158 beforeEach ( ( ) => {
11501159 uc = UnitCode . parse ( '5' ) ;
1160+ mt = uc . getMinimumTick ( 1 ) ;
11511161 } ) ;
11521162
11531163 it ( 'A value of 110.328125 should be rounded to 110.328125' , ( ) => {
1154- expect ( uc . roundToNearestTick ( 110.328125 , 1 ) ) . toEqual ( 110.328125 ) ;
1164+ expect ( uc . roundToNearestTick ( 110.328125 , mt ) ) . toEqual ( 110.328125 ) ;
11551165 } ) ;
11561166
11571167 it ( 'A value of 110.34375 should be rounded to 110.34375' , ( ) => {
1158- expect ( uc . roundToNearestTick ( 110.34375 , 1 ) ) . toEqual ( 110.34375 ) ;
1168+ expect ( uc . roundToNearestTick ( 110.34375 , mt ) ) . toEqual ( 110.34375 ) ;
11591169 } ) ;
11601170
11611171 it ( 'A value of 110.328126 should be rounded to 110.328125' , ( ) => {
1162- expect ( uc . roundToNearestTick ( 110.328126 , 1 ) ) . toEqual ( 110.328125 ) ;
1172+ expect ( uc . roundToNearestTick ( 110.328126 , mt ) ) . toEqual ( 110.328125 ) ;
11631173 } ) ;
11641174
11651175 it ( 'A value of 110.34374 should be rounded to 110.34375' , ( ) => {
1166- expect ( uc . roundToNearestTick ( 110.34374 , 1 ) ) . toEqual ( 110.34375 ) ;
1176+ expect ( uc . roundToNearestTick ( 110.34374 , mt ) ) . toEqual ( 110.34375 ) ;
11671177 } ) ;
11681178
11691179 it ( 'A value of 110.34374 should be rounded to 110.328125 (when using "roundDown" option)' , ( ) => {
1170- expect ( uc . roundToNearestTick ( 110.34374 , 1 , true ) ) . toEqual ( 110.328125 ) ;
1180+ expect ( uc . roundToNearestTick ( 110.34374 , mt , true ) ) . toEqual ( 110.328125 ) ;
11711181 } ) ;
11721182 } ) ;
11731183} ) ;
0 commit comments