Adding an assert makes a test fail

⚓ Rust    📅 2025-09-20    👤 surdeus    👁️ 8      

surdeus

Warning

This post was published 43 days ago. The information described in this article may have changed.

Hello! I have a test that I'm running whose outcome appears to be affected by how I construct the input. Here's the short story:

  • I construct a linearly-spaced ndarray in two different ways: Construction A and Construction B
  • These result in the exact same values
  • I have a previously-existing test that works on Construction A, but not on Construction B
  • What's worse, simply asserting that the two constructions are equal in value causes the original test to start failing on Construction A.

Here's a main.rs to demonstrate:

Rust Code (click for more details)

I'm really stumped by what could be causing this. My best guess right now is some sort of difference in compiler optimizations? Any help would be greatly appreciated.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed