MCPcopy Create free account
hub / github.com/apple/axlearn / test_invalid_indices

Method test_invalid_indices

axlearn/common/segment_tree_test.py:116–132  ·  view source on GitHub ↗

Test behavior with invalid indices.

(self)

Source from the content-addressed store, hash-verified

114 self.assertEqual(single_tree.query_range(0, 0), 10)
115
116 def test_invalid_indices(self):
117 """Test behavior with invalid indices."""
118 tree = SegmentTree[int](max_index=5, operation=max, default_value=0)
119
120 with self.assertRaises(IndexError):
121 tree.update(-1, 100)
122 with self.assertRaises(IndexError):
123 tree.update(6, 100)
124
125 # Invalid range queries should return default
126 self.assertEqual(tree.query_range(-1, 0), 0)
127 self.assertEqual(tree.query_range(5, 6), 0)
128 self.assertEqual(tree.query_range(3, 2), 0) # left > right
129
130 # Invalid get_value should return default
131 self.assertEqual(tree.get_value(-1), 0)
132 self.assertEqual(tree.get_value(6), 0)
133
134 def test_negative_value_validation(self):
135 """Test that negative values are properly validated for max operations."""

Callers

nothing calls this directly

Calls 3

query_rangeMethod · 0.80
get_valueMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected