Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes with standard equality check #16

Open
turion opened this issue Nov 14, 2022 · 1 comment
Open

Crashes with standard equality check #16

turion opened this issue Nov 14, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@turion
Copy link

turion commented Nov 14, 2022

I applied this change:

diff --git a/test/closed_intervals_test.exs b/test/closed_intervals_test.exs
index 36f1c90..9348dbb 100644
--- a/test/closed_intervals_test.exs
+++ b/test/closed_intervals_test.exs
@@ -50,7 +50,7 @@ defmodule ClosedIntervalsTest do
     end
 
     test "get_interval" do
-      tree = from([1, 2, 3, 4])
+      tree = from([1, 2, 3, 4], eq: &==/2)
       assert {1, 2} == get_interval(tree, 2)
       assert {1, 2} == get_interval(tree, 1.5)
       assert {2, 3} == get_interval(tree, 2.5)

It crashes:

$ mix test test/closed_intervals_test.exs:52
Excluding tags: [:test]
Including tags: [line: "52"]



  1) test default order get_interval (ClosedIntervalsTest)
     test/closed_intervals_test.exs:52
     ** (CaseClauseError) no case clause matching: [{1, 2}, {2, 3}]
     code: assert {1, 2} == get_interval(tree, 2)
     stacktrace:
       (closed_intervals 0.5.0) lib/closed_intervals.ex:166: ClosedIntervals.get_interval/2
       test/closed_intervals_test.exs:54: (test)



Finished in 0.1 seconds (0.00s async, 0.1s sync)
11 doctests, 2 properties, 6 tests, 1 failure, 18 excluded

Randomized with seed 659730

I find that surprising since this is the most straightforward equality function I can think of. Found while working at a PR for #15

@turion turion mentioned this issue Nov 14, 2022
6 tasks
@evnu
Copy link
Owner

evnu commented Nov 14, 2022

Interesting. This crashes because the interval for 2 is not unique. Maybe this should be signaled instead of crashing.

@evnu evnu added the documentation Improvements or additions to documentation label Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants