Skip to content

Commit

Permalink
Add FSharp.Core tests for int64 and uint64 parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdziadkiewicz committed Mar 22, 2019
1 parent d5c12e0 commit 21f734e
Show file tree
Hide file tree
Showing 3 changed files with 575 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/FSharp.Core.UnitTests/FSharp.Core.UnitTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<Compile Include="FSharp.Core\ComparersRegression.fs" />
<Compile Include="FSharp.Core\DiscrimantedUnionType.fs" />
<Compile Include="FSharp.Core\RecordTypes.fs" />
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\NumberParsingUnchecked.fs" />
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\NumberParsingChecked.fs" />
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\BigIntType.fs" />
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\IntConversions.fs" />
<Compile Include="FSharp.Core\Microsoft.FSharp.Core\IntConversionsGenerated.fs" />
Expand Down
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)
Loading

0 comments on commit 21f734e

Please sign in to comment.