Skip to content

AboutNumbers wrong types #474

@magoerlich

Description

@magoerlich

$BigValue | Should -BeOfType [long]
$BigValue | Should -BeGreaterThan $MaxValue
$SmallValue = __
$SmallValue | Should -BeOfType [long]
$SmallValue | Should -BeLessThan $MinValue

Is this part correct about numbers getting converted to longs?

Because no matter, what I try for me it's always a double

Code:

$BigValue = [int]::MaxValue + 200
$BigValue | Should -BeOfType [long]
$BigValue | Should -BeGreaterThan $MaxValue

Output:

Expected the value to have type [long] or any of its subtypes, but got 2147483847 with type [double].

Starting with a short and increasing it to >MaxValue behaves the same:

~\PSKoans
❯ $int = [int]::MaxValue

~\PSKoans
❯ $int.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int32                                    System.ValueType


~\PSKoans
❯ $int += 100

~\PSKoans
❯ $int.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Double                                   System.ValueType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions