-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FSharp.Core tests for int64 and uint64 parsing.
- Loading branch information
1 parent
d5c12e0
commit 21f734e
Showing
3 changed files
with
575 additions
and
0 deletions.
There are no files selected for viewing
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
287 changes: 287 additions & 0 deletions
287
tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Core/NumberParsingChecked.fs
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,287 @@ | ||
module FSharp.Core.UnitTests.FSharp_Core.FSharp.Core.NumberParsingChecked | ||
open System | ||
open NUnit.Framework | ||
open FSharp.Core.UnitTests.LibraryTestFx | ||
open Checked | ||
|
||
module Int64Tests = | ||
module Denary = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "9223372036854775808" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "9223372036854775807" | ||
let result = int64 d | ||
Assert.AreEqual(9223372036854775807L, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-9223372036854775809" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "-9223372036854775808" | ||
let result = int64 d | ||
Assert.AreEqual(-9223372036854775808L, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
module Binary = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" | ||
let result = int64 d | ||
Assert.AreEqual(9223372036854775807L, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000001" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "-0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000" | ||
let result = int64 d | ||
Assert.AreEqual(-9223372036854775808L, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0b0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0b0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
module Octal = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0o1_000_000_000_000_000_000_000" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0o777_777_777_777_777_777_777" | ||
let result = int64 d | ||
Assert.AreEqual(9223372036854775807L, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0o1_000_000_000_000_000_000_001" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "-0o1_000_000_000_000_000_000_000" | ||
let result = int64 d | ||
Assert.AreEqual(-9223372036854775808L, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0o0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0o0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
module Hexadecimal = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0x80_00_00_00_00_00_00_00" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0x7F_FF_FF_FF_FF_FF_FF_FF" | ||
let result = int64 d | ||
Assert.AreEqual(9223372036854775807L, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0x80_00_00_00_00_00_00_01" | ||
CheckThrowsExn<OverflowException>(fun() -> int64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "-0x80_00_00_00_00_00_00_00" | ||
let result = int64 d | ||
Assert.AreEqual(-9223372036854775808L, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0x0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0x0" | ||
let result = int64 d | ||
Assert.AreEqual(0L, result) | ||
|
||
module UInt64Tests = | ||
module Denary = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "18446744073709551616" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "18446744073709551615" | ||
let result = uint64 d | ||
Assert.AreEqual(18446744073709551615UL, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-1" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
module Binary = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111" | ||
let result = uint64 d | ||
Assert.AreEqual(18446744073709551615UL, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0b1" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "0b0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0b0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0b0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
module Octal = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0o2_000_000_000_000_000_000_000" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0o1_777_777_777_777_777_777_777" | ||
let result = uint64 d | ||
Assert.AreEqual(18446744073709551615UL, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0o1" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "0o0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0o0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0o0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
module Hexadecimal = | ||
[<Test>] | ||
let ``Max + 1`` () = | ||
let d = "0x1_00_00_00_00_00_00_00_00" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Max`` () = | ||
let d = "0xFF_FF_FF_FF_FF_FF_FF_FF" | ||
let result = uint64 d | ||
Assert.AreEqual(18446744073709551615UL, result) | ||
|
||
[<Test>] | ||
let ``Min - 1`` () = | ||
let d = "-0x1" | ||
CheckThrowsExn<OverflowException>(fun() -> uint64 d |> ignore) | ||
|
||
[<Test>] | ||
let ``Min`` () = | ||
let d = "0x0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Zero`` () = | ||
let d = "0x0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) | ||
|
||
[<Test>] | ||
let ``Minus Zero`` () = | ||
let d = "-0x0" | ||
let result = uint64 d | ||
Assert.AreEqual(0UL, result) |
Oops, something went wrong.