@@ -773,18 +773,51 @@ defmodule Module.Types.PatternTest do
773773 end
774774 end
775775
776- describe "equality in guards" do
777- test "length" do
776+ describe "comparison in guards" do
777+ test "length equality " do
778778 assert typecheck! ( [ x ] , length ( x ) != 0 , x ) == dynamic ( non_empty_list ( term ( ) ) )
779779 assert typecheck! ( [ x ] , not ( length ( x ) != 0 ) , x ) == dynamic ( empty_list ( ) )
780780
781781 assert typecheck! ( [ x ] , 0 != length ( x ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
782782 assert typecheck! ( [ x ] , not ( 0 != length ( x ) ) , x ) == dynamic ( empty_list ( ) )
783783 end
784784
785+ test "length ordered" do
786+ assert typecheck! ( [ x ] , length ( x ) < 0 , x ) == dynamic ( list ( term ( ) ) )
787+ assert typecheck! ( [ x ] , length ( x ) >= 0 , x ) == dynamic ( list ( term ( ) ) )
788+ assert typecheck! ( [ x ] , length ( x ) <= 0 , x ) == dynamic ( empty_list ( ) )
789+
790+ assert typecheck! ( [ x ] , 0 <= length ( x ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
791+ assert typecheck! ( [ x ] , 0 >= length ( x ) , x ) == dynamic ( list ( term ( ) ) )
792+ assert typecheck! ( [ x ] , 0 < length ( x ) , x ) == dynamic ( list ( term ( ) ) )
793+ assert typecheck! ( [ x ] , 0 > length ( x ) , x ) == dynamic ( empty_list ( ) )
794+
795+ assert typecheck! ( [ x ] , not ( length ( x ) > 0 ) , x ) == dynamic ( empty_list ( ) )
796+ assert typecheck! ( [ x ] , not ( length ( x ) < 0 ) , x ) == dynamic ( list ( term ( ) ) )
797+ assert typecheck! ( [ x ] , not ( length ( x ) >= 0 ) , x ) == dynamic ( list ( term ( ) ) )
798+ assert typecheck! ( [ x ] , not ( length ( x ) <= 0 ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
799+
800+ assert typecheck! ( [ x ] , length ( x ) < 1 , x ) == dynamic ( empty_list ( ) )
801+
802+ assert typecheck! ( [ x ] , length ( x ) > 2 , x ) == dynamic ( non_empty_list ( term ( ) ) )
803+ assert typecheck! ( [ x ] , length ( x ) < 2 , x ) == dynamic ( list ( term ( ) ) )
804+ assert typecheck! ( [ x ] , length ( x ) >= 2 , x ) == dynamic ( non_empty_list ( term ( ) ) )
805+ assert typecheck! ( [ x ] , length ( x ) <= 2 , x ) == dynamic ( list ( term ( ) ) )
806+
807+ assert typecheck! ( [ x ] , 2 <= length ( x ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
808+ assert typecheck! ( [ x ] , 2 >= length ( x ) , x ) == dynamic ( list ( term ( ) ) )
809+ assert typecheck! ( [ x ] , 2 < length ( x ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
810+ assert typecheck! ( [ x ] , 2 > length ( x ) , x ) == dynamic ( list ( term ( ) ) )
811+
812+ assert typecheck! ( [ x ] , not ( length ( x ) > 2 ) , x ) == dynamic ( list ( term ( ) ) )
813+ assert typecheck! ( [ x ] , not ( length ( x ) < 2 ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
814+ assert typecheck! ( [ x ] , not ( length ( x ) >= 2 ) , x ) == dynamic ( list ( term ( ) ) )
815+ assert typecheck! ( [ x ] , not ( length ( x ) <= 2 ) , x ) == dynamic ( non_empty_list ( term ( ) ) )
816+ end
817+
785818 @ non_empty_map difference ( open_map ( ) , empty_map ( ) )
786819
787- test "map_size" do
820+ test "map_size equality " do
788821 assert typecheck! ( [ x ] , map_size ( x ) == 0 , x ) == dynamic ( empty_map ( ) )
789822 assert typecheck! ( [ x ] , map_size ( x ) != 0 , x ) == dynamic ( @ non_empty_map )
790823 assert typecheck! ( [ x ] , not ( map_size ( x ) == 0 ) , x ) == dynamic ( @ non_empty_map )
@@ -796,10 +829,49 @@ defmodule Module.Types.PatternTest do
796829 assert typecheck! ( [ x ] , not ( 0 != map_size ( x ) ) , x ) == dynamic ( empty_map ( ) )
797830 end
798831
832+ test "map_size ordered" do
833+ assert typecheck! ( [ x ] , map_size ( x ) > 0 , x ) == dynamic ( @ non_empty_map )
834+ assert typecheck! ( [ x ] , map_size ( x ) < 0 , x ) == dynamic ( open_map ( ) )
835+ assert typecheck! ( [ x ] , map_size ( x ) >= 0 , x ) == dynamic ( open_map ( ) )
836+ assert typecheck! ( [ x ] , map_size ( x ) <= 0 , x ) == dynamic ( empty_map ( ) )
837+
838+ assert typecheck! ( [ x ] , 0 <= map_size ( x ) , x ) == dynamic ( @ non_empty_map )
839+ assert typecheck! ( [ x ] , 0 >= map_size ( x ) , x ) == dynamic ( open_map ( ) )
840+ assert typecheck! ( [ x ] , 0 < map_size ( x ) , x ) == dynamic ( open_map ( ) )
841+ assert typecheck! ( [ x ] , 0 > map_size ( x ) , x ) == dynamic ( empty_map ( ) )
842+
843+ assert typecheck! ( [ x ] , not ( map_size ( x ) > 0 ) , x ) == dynamic ( empty_map ( ) )
844+ assert typecheck! ( [ x ] , not ( map_size ( x ) < 0 ) , x ) == dynamic ( open_map ( ) )
845+ assert typecheck! ( [ x ] , not ( map_size ( x ) >= 0 ) , x ) == dynamic ( open_map ( ) )
846+ assert typecheck! ( [ x ] , not ( map_size ( x ) <= 0 ) , x ) == dynamic ( @ non_empty_map )
847+
848+ assert typecheck! ( [ x ] , map_size ( x ) < 1 , x ) == dynamic ( empty_map ( ) )
849+
850+ assert typecheck! ( [ x ] , map_size ( x ) > 2 , x ) == dynamic ( @ non_empty_map )
851+ assert typecheck! ( [ x ] , map_size ( x ) < 2 , x ) == dynamic ( open_map ( ) )
852+ assert typecheck! ( [ x ] , map_size ( x ) >= 2 , x ) == dynamic ( @ non_empty_map )
853+ assert typecheck! ( [ x ] , map_size ( x ) <= 2 , x ) == dynamic ( open_map ( ) )
854+
855+ assert typecheck! ( [ x ] , 2 <= map_size ( x ) , x ) == dynamic ( @ non_empty_map )
856+ assert typecheck! ( [ x ] , 2 >= map_size ( x ) , x ) == dynamic ( open_map ( ) )
857+ assert typecheck! ( [ x ] , 2 < map_size ( x ) , x ) == dynamic ( @ non_empty_map )
858+ assert typecheck! ( [ x ] , 2 > map_size ( x ) , x ) == dynamic ( open_map ( ) )
859+
860+ assert typecheck! ( [ x ] , not ( map_size ( x ) > 2 ) , x ) == dynamic ( open_map ( ) )
861+ assert typecheck! ( [ x ] , not ( map_size ( x ) < 2 ) , x ) == dynamic ( @ non_empty_map )
862+ assert typecheck! ( [ x ] , not ( map_size ( x ) >= 2 ) , x ) == dynamic ( open_map ( ) )
863+ assert typecheck! ( [ x ] , not ( map_size ( x ) <= 2 ) , x ) == dynamic ( @ non_empty_map )
864+ end
865+
799866 @ non_empty_tuple difference ( open_tuple ( [ ] ) , tuple ( [ ] ) )
800- @ non_empty_binary_tuple difference ( open_tuple ( [ ] ) , tuple ( [ term ( ) , term ( ) ] ) )
867+ @ non_binary_tuple difference ( open_tuple ( [ ] ) , tuple ( [ term ( ) , term ( ) ] ) )
868+
869+ @ open_binary_tuple open_tuple ( [ term ( ) , term ( ) ] )
870+ @ open_ternary_tuple open_tuple ( [ term ( ) , term ( ) , term ( ) ] )
871+ @ non_open_binary_tuple difference ( open_tuple ( [ ] ) , open_tuple ( [ term ( ) , term ( ) ] ) )
872+ @ non_open_ternary_tuple difference ( open_tuple ( [ ] ) , open_tuple ( [ term ( ) , term ( ) , term ( ) ] ) )
801873
802- test "tuple_size" do
874+ test "tuple_size equality " do
803875 assert typecheck! ( [ x ] , tuple_size ( x ) == 0 , x ) == dynamic ( tuple ( [ ] ) )
804876 assert typecheck! ( [ x ] , tuple_size ( x ) != 0 , x ) == dynamic ( @ non_empty_tuple )
805877 assert typecheck! ( [ x ] , not ( tuple_size ( x ) == 0 ) , x ) == dynamic ( @ non_empty_tuple )
@@ -811,14 +883,46 @@ defmodule Module.Types.PatternTest do
811883 assert typecheck! ( [ x ] , not ( 0 != tuple_size ( x ) ) , x ) == dynamic ( tuple ( [ ] ) )
812884
813885 assert typecheck! ( [ x ] , tuple_size ( x ) == 2 , x ) == dynamic ( tuple ( [ term ( ) , term ( ) ] ) )
814- assert typecheck! ( [ x ] , tuple_size ( x ) != 2 , x ) == dynamic ( @ non_empty_binary_tuple )
815- assert typecheck! ( [ x ] , not ( tuple_size ( x ) == 2 ) , x ) == dynamic ( @ non_empty_binary_tuple )
886+ assert typecheck! ( [ x ] , tuple_size ( x ) != 2 , x ) == dynamic ( @ non_binary_tuple )
887+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) == 2 ) , x ) == dynamic ( @ non_binary_tuple )
816888 assert typecheck! ( [ x ] , not ( tuple_size ( x ) != 2 ) , x ) == dynamic ( tuple ( [ term ( ) , term ( ) ] ) )
817889
818890 assert typecheck! ( [ x ] , 2 == tuple_size ( x ) , x ) == dynamic ( tuple ( [ term ( ) , term ( ) ] ) )
819- assert typecheck! ( [ x ] , 2 != tuple_size ( x ) , x ) == dynamic ( @ non_empty_binary_tuple )
820- assert typecheck! ( [ x ] , not ( 2 == tuple_size ( x ) ) , x ) == dynamic ( @ non_empty_binary_tuple )
891+ assert typecheck! ( [ x ] , 2 != tuple_size ( x ) , x ) == dynamic ( @ non_binary_tuple )
892+ assert typecheck! ( [ x ] , not ( 2 == tuple_size ( x ) ) , x ) == dynamic ( @ non_binary_tuple )
821893 assert typecheck! ( [ x ] , not ( 2 != tuple_size ( x ) ) , x ) == dynamic ( tuple ( [ term ( ) , term ( ) ] ) )
822894 end
895+
896+ test "tuple_size ordered" do
897+ assert typecheck! ( [ x ] , tuple_size ( x ) > 0 , x ) == dynamic ( open_tuple ( [ term ( ) ] ) )
898+ assert typecheck! ( [ x ] , tuple_size ( x ) < 0 , x ) == dynamic ( open_tuple ( [ ] ) )
899+ assert typecheck! ( [ x ] , tuple_size ( x ) >= 0 , x ) == dynamic ( open_tuple ( [ ] ) )
900+ assert typecheck! ( [ x ] , tuple_size ( x ) <= 0 , x ) == dynamic ( tuple ( [ ] ) )
901+
902+ assert typecheck! ( [ x ] , 0 <= tuple_size ( x ) , x ) == dynamic ( open_tuple ( [ term ( ) ] ) )
903+ assert typecheck! ( [ x ] , 0 >= tuple_size ( x ) , x ) == dynamic ( open_tuple ( [ ] ) )
904+ assert typecheck! ( [ x ] , 0 < tuple_size ( x ) , x ) == dynamic ( open_tuple ( [ ] ) )
905+ assert typecheck! ( [ x ] , 0 > tuple_size ( x ) , x ) == dynamic ( tuple ( [ ] ) )
906+
907+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) > 0 ) , x ) == dynamic ( tuple ( [ ] ) )
908+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) < 0 ) , x ) == dynamic ( open_tuple ( [ ] ) )
909+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) >= 0 ) , x ) == dynamic ( open_tuple ( [ ] ) )
910+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) <= 0 ) , x ) == dynamic ( open_tuple ( [ term ( ) ] ) )
911+
912+ assert typecheck! ( [ x ] , tuple_size ( x ) > 2 , x ) == dynamic ( @ open_ternary_tuple )
913+ assert typecheck! ( [ x ] , tuple_size ( x ) < 2 , x ) == dynamic ( @ non_open_binary_tuple )
914+ assert typecheck! ( [ x ] , tuple_size ( x ) >= 2 , x ) == dynamic ( @ open_binary_tuple )
915+ assert typecheck! ( [ x ] , tuple_size ( x ) <= 2 , x ) == dynamic ( @ non_open_ternary_tuple )
916+
917+ assert typecheck! ( [ x ] , 2 <= tuple_size ( x ) , x ) == dynamic ( @ open_ternary_tuple )
918+ assert typecheck! ( [ x ] , 2 >= tuple_size ( x ) , x ) == dynamic ( @ non_open_binary_tuple )
919+ assert typecheck! ( [ x ] , 2 < tuple_size ( x ) , x ) == dynamic ( @ open_binary_tuple )
920+ assert typecheck! ( [ x ] , 2 > tuple_size ( x ) , x ) == dynamic ( @ non_open_ternary_tuple )
921+
922+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) > 2 ) , x ) == dynamic ( @ non_open_ternary_tuple )
923+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) < 2 ) , x ) == dynamic ( @ open_binary_tuple )
924+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) >= 2 ) , x ) == dynamic ( @ non_open_binary_tuple )
925+ assert typecheck! ( [ x ] , not ( tuple_size ( x ) <= 2 ) , x ) == dynamic ( @ open_ternary_tuple )
926+ end
823927 end
824928end
0 commit comments