mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-04-29 00:59:07 -05:00
fix: update test assertion for new error message format
The reshape error message was updated to the 3-part educational pattern, but the integration test was still checking for the old message text. Updated to use case-insensitive matching.
This commit is contained in:
@@ -322,8 +322,12 @@ def reshape(self, *shape):
|
||||
|
||||
# Validate total elements match
|
||||
if np.prod(new_shape) != self.size:
|
||||
target_size = int(np.prod(new_shape))
|
||||
raise ValueError(
|
||||
f"Total elements must match: {self.size} ≠ {int(np.prod(new_shape))}"
|
||||
f"Cannot reshape {self.shape} to {new_shape}\n"
|
||||
f" ❌ Element count mismatch: {self.size} elements vs {target_size} elements\n"
|
||||
f" 💡 Reshape preserves data, so total elements must stay the same\n"
|
||||
f" 🔧 Use -1 to infer a dimension: reshape(-1, {new_shape[-1] if len(new_shape) > 0 else 1}) lets NumPy calculate"
|
||||
)
|
||||
|
||||
reshaped_data = np.reshape(self.data, new_shape)
|
||||
|
||||
@@ -232,7 +232,7 @@ def test_unit_shape_manipulation():
|
||||
t.reshape(2, 2) # 6 elements can't fit in 2×2=4
|
||||
assert False, "Should have raised ValueError"
|
||||
except ValueError as e:
|
||||
assert "Total elements must match" in str(e)
|
||||
assert "element count mismatch" in str(e).lower()
|
||||
|
||||
print("✅ Shape manipulation works!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user