Skip to content

Commit

Permalink
Use approximate comparisons in floating point test
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Oct 30, 2023
1 parent 21ef457 commit 17ca888
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions brian2/tests/test_neurongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,25 +1120,25 @@ def test_state_variables():

# Calculating with state variables should work too
# With units
assert all(G.v - G.v == 0)
assert all(G.v - G.v[:] == 0 * mV)
assert all(G.v[:] - G.v == 0 * mV)
assert all(G.v + 70 * mV == G.v[:] + 70 * mV)
assert all(70 * mV + G.v == G.v[:] + 70 * mV)
assert all(G.v + G.v == 2 * G.v)
assert all(G.v / 2.0 == 0.5 * G.v)
assert all(1.0 / G.v == 1.0 / G.v[:])
assert_allclose(G.v - G.v, 0 * mV)
assert_allclose(G.v - G.v[:], 0 * mV)
assert_allclose(G.v[:] - G.v, 0 * mV)
assert_allclose(G.v + 70 * mV, G.v[:] + 70 * mV)
assert_allclose(70 * mV + G.v, G.v[:] + 70 * mV)
assert_allclose(G.v + G.v, 2 * G.v)
assert_allclose(G.v / 2.0, 0.5 * G.v)
assert_allclose(1.0 / G.v, 1.0 / G.v[:])
assert_allclose((-G.v)[:], -G.v[:])
assert_allclose((+G.v)[:], G.v[:])
# Without units
assert all(G.v_ - G.v_ == 0)
assert all(G.v_ - G.v_[:] == 0)
assert all(G.v_[:] - G.v_ == 0)
assert all(G.v_ + float(70 * mV) == G.v_[:] + float(70 * mV))
assert all(float(70 * mV) + G.v_ == G.v_[:] + float(70 * mV))
assert all(G.v_ + G.v_ == 2 * G.v_)
assert all(G.v_ / 2.0 == 0.5 * G.v_)
assert all(1.0 / G.v_ == 1.0 / G.v_[:])
assert_allclose(G.v_ - G.v_, 0)
assert_allclose(G.v_ - G.v_[:], 0)
assert_allclose(G.v_[:] - G.v_, 0)
assert_allclose(G.v_ + float(70 * mV), G.v_[:] + float(70 * mV))
assert_allclose(float(70 * mV) + G.v_, G.v_[:] + float(70 * mV))
assert_allclose(G.v_ + G.v_, 2 * G.v_)
assert_allclose(G.v_ / 2.0, 0.5 * G.v_)
assert_allclose(1.0 / G.v_, 1.0 / G.v_[:])
assert_allclose((-G.v)[:], -G.v[:])
assert_allclose((+G.v)[:], G.v[:])

Expand Down

0 comments on commit 17ca888

Please sign in to comment.