MCPcopy
hub / github.com/reflex-dev/reflex / test_array_operations

Function test_array_operations

tests/units/test_var.py:1096–1117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1094
1095
1096def test_array_operations():
1097 array_var = LiteralArrayVar.create([1, 2, 3, 4, 5])
1098
1099 assert str(array_var.length()) == "[1, 2, 3, 4, 5].length"
1100 assert str(array_var.contains(3)) == "[1, 2, 3, 4, 5].includes(3)"
1101 assert str(array_var.reverse()) == "[1, 2, 3, 4, 5].slice().reverse()"
1102 assert (
1103 str(ArrayVar.range(10))
1104 == "Array.from({ length: Math.ceil((10 - 0) / 1) }, (_, i) => 0 + i * 1)"
1105 )
1106 assert (
1107 str(ArrayVar.range(1, 10))
1108 == "Array.from({ length: Math.ceil((10 - 1) / 1) }, (_, i) => 1 + i * 1)"
1109 )
1110 assert (
1111 str(ArrayVar.range(1, 10, 2))
1112 == "Array.from({ length: Math.ceil((10 - 1) / 2) }, (_, i) => 1 + i * 2)"
1113 )
1114 assert (
1115 str(ArrayVar.range(1, 10, -1))
1116 == "Array.from({ length: Math.ceil((10 - 1) / -1) }, (_, i) => 1 + i * -1)"
1117 )
1118
1119
1120def test_object_operations():

Callers

nothing calls this directly

Calls 5

reverseMethod · 0.80
createMethod · 0.45
lengthMethod · 0.45
containsMethod · 0.45
rangeMethod · 0.45

Tested by

no test coverage detected