Hello, the Should Throw works ok for me.
Although the results might seem weird, the different comparisons work as they should:
When the input to an operator is a scalar value, comparison operators
return a Boolean value. When the input is a collection of values, the
comparison operators return any matching values. If there are no matches
in a collection, comparison operators do not return anything.
The exceptions are the containment operators (-Contains, -NotContains),
the In operators (-In, -NotIn), and the type operators (-Is, -IsNot),
which always return a Boolean value.
1 -eq 1 returns true because you provide scalar values.
The hash tables are not equal because they are two different objects. When comparing objects (with exception for some types, for example those implementing IComparable) their references are compared not their values.
The first array example does not return anything because the first array is expanded (see above) and the items contained in it are compared with the value on the right side. There you provide new array object so the reference is different and no match is found. To get a match you'd have to wrap the array in array and then compare it with the same object:
$item = @(1)
$array = @($null)
$areay[0] = $item
$array -eq $item # returns the object in $item
The second array example: The values in array are expanded and 1 is equal to the 1 so 1 is output.
1 -eq @(1) The type of the left operand determines the type in which the operands are compared. 1 is integer so cast to integer is made. [int]@(1) silently fails so the result is false. try '1' -eq @(1), in that case cast to string is made which returns '1', the values are equal and the result is true.
hope this made it clearer.