forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Add tests for new rounding modes
See tc39/proposal-temporal#2262 which added new rounding modes from NumberFormat V3. These tests use the same format as the previous ones. The tests for the "half" rounding modes aren't very good yet, as they don't show any of the differences between the tiebreaking schemes; there aren't any ties in the data to be broken. (Except in .toString().) A subsequent commit will correct this.
- Loading branch information
Showing
105 changed files
with
3,865 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Tests calculations with roundingMode "expand". | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); | ||
const relativeTo = new Temporal.PlainDate(2020, 1, 1); | ||
|
||
const expected = [ | ||
["years", [6], [-6]], | ||
["months", [5, 8], [-5, -8]], | ||
["weeks", [5, 6, 9], [-5, -6, -9]], | ||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]], | ||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], | ||
["minutes", [5, 6, 7, 9, 16, 31], [-5, -6, -7, -9, -16, -31]], | ||
["seconds", [5, 6, 7, 9, 16, 30, 21], [-5, -6, -7, -9, -16, -30, -21]], | ||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], | ||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], | ||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], | ||
]; | ||
|
||
const roundingMode = "expand"; | ||
|
||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { | ||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; | ||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; | ||
TemporalHelpers.assertDuration( | ||
instance.round({ smallestUnit, relativeTo, roundingMode }), | ||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` | ||
); | ||
TemporalHelpers.assertDuration( | ||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }), | ||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, | ||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Tests calculations with roundingMode "halfCeil". | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); | ||
const relativeTo = new Temporal.PlainDate(2020, 1, 1); | ||
|
||
const expected = [ | ||
["years", [6], [-6]], | ||
["months", [5, 8], [-5, -8]], | ||
["weeks", [5, 6, 8], [-5, -6, -8]], | ||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]], | ||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], | ||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], | ||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], | ||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], | ||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], | ||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], | ||
]; | ||
|
||
const roundingMode = "halfCeil"; | ||
|
||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { | ||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; | ||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; | ||
TemporalHelpers.assertDuration( | ||
instance.round({ smallestUnit, relativeTo, roundingMode }), | ||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` | ||
); | ||
TemporalHelpers.assertDuration( | ||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }), | ||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, | ||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Tests calculations with roundingMode "halfEven". | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); | ||
const relativeTo = new Temporal.PlainDate(2020, 1, 1); | ||
|
||
const expected = [ | ||
["years", [6], [-6]], | ||
["months", [5, 8], [-5, -8]], | ||
["weeks", [5, 6, 8], [-5, -6, -8]], | ||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]], | ||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], | ||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], | ||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], | ||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], | ||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], | ||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], | ||
]; | ||
|
||
const roundingMode = "halfEven"; | ||
|
||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { | ||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; | ||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; | ||
TemporalHelpers.assertDuration( | ||
instance.round({ smallestUnit, relativeTo, roundingMode }), | ||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` | ||
); | ||
TemporalHelpers.assertDuration( | ||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }), | ||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, | ||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Tests calculations with roundingMode "halfFloor". | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); | ||
const relativeTo = new Temporal.PlainDate(2020, 1, 1); | ||
|
||
const expected = [ | ||
["years", [6], [-6]], | ||
["months", [5, 8], [-5, -8]], | ||
["weeks", [5, 6, 8], [-5, -6, -8]], | ||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]], | ||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], | ||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], | ||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], | ||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], | ||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], | ||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], | ||
]; | ||
|
||
const roundingMode = "halfFloor"; | ||
|
||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { | ||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; | ||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; | ||
TemporalHelpers.assertDuration( | ||
instance.round({ smallestUnit, relativeTo, roundingMode }), | ||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` | ||
); | ||
TemporalHelpers.assertDuration( | ||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }), | ||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, | ||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` | ||
); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: Tests calculations with roundingMode "halfTrunc". | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); | ||
const relativeTo = new Temporal.PlainDate(2020, 1, 1); | ||
|
||
const expected = [ | ||
["years", [6], [-6]], | ||
["months", [5, 8], [-5, -8]], | ||
["weeks", [5, 6, 8], [-5, -6, -8]], | ||
["days", [5, 6, 7, 10], [-5, -6, -7, -10]], | ||
["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], | ||
["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], | ||
["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], | ||
["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], | ||
["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], | ||
["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], | ||
]; | ||
|
||
const roundingMode = "halfTrunc"; | ||
|
||
expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { | ||
const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; | ||
const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; | ||
TemporalHelpers.assertDuration( | ||
instance.round({ smallestUnit, relativeTo, roundingMode }), | ||
py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` | ||
); | ||
TemporalHelpers.assertDuration( | ||
instance.negated().round({ smallestUnit, relativeTo, roundingMode }), | ||
ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, | ||
`rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` | ||
); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.round | ||
description: Tests calculations with roundingMode "expand". | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); | ||
|
||
const expected = [ | ||
["hour", 217177200_000_000_000n /* 1976-11-18T15:00:00Z */], | ||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], | ||
["second", 217175011_000_000_000n /* 1976-11-18T14:23:31Z */], | ||
["millisecond", 217175010_124_000_000n /* 1976-11-18T14:23:30.124Z */], | ||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], | ||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], | ||
]; | ||
|
||
const roundingMode = "expand"; | ||
|
||
expected.forEach(([smallestUnit, expected]) => { | ||
assert.sameValue( | ||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds, | ||
expected, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})` | ||
); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.round | ||
description: Tests calculations with roundingMode "halfCeil". | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); | ||
|
||
const expected = [ | ||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], | ||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], | ||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], | ||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], | ||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], | ||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], | ||
]; | ||
|
||
const roundingMode = "halfCeil"; | ||
|
||
expected.forEach(([smallestUnit, expected]) => { | ||
assert.sameValue( | ||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds, | ||
expected, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})` | ||
); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.round | ||
description: Tests calculations with roundingMode "halfEven". | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); | ||
|
||
const expected = [ | ||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], | ||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], | ||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], | ||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], | ||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], | ||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], | ||
]; | ||
|
||
const roundingMode = "halfEven"; | ||
|
||
expected.forEach(([smallestUnit, expected]) => { | ||
assert.sameValue( | ||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds, | ||
expected, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})` | ||
); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.round | ||
description: Tests calculations with roundingMode "halfFloor". | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); | ||
|
||
const expected = [ | ||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], | ||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], | ||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], | ||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], | ||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], | ||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], | ||
]; | ||
|
||
const roundingMode = "halfFloor"; | ||
|
||
expected.forEach(([smallestUnit, expected]) => { | ||
assert.sameValue( | ||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds, | ||
expected, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})` | ||
); | ||
}); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.round | ||
description: Tests calculations with roundingMode "halfTrunc". | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); | ||
|
||
const expected = [ | ||
["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], | ||
["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], | ||
["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], | ||
["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], | ||
["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], | ||
["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], | ||
]; | ||
|
||
const roundingMode = "halfTrunc"; | ||
|
||
expected.forEach(([smallestUnit, expected]) => { | ||
assert.sameValue( | ||
instance.round({ smallestUnit, roundingMode }).epochNanoseconds, | ||
expected, | ||
`rounds to ${smallestUnit} (roundingMode = ${roundingMode})` | ||
); | ||
}); |
Oops, something went wrong.