Skip to content
Snippets Groups Projects
Commit bd876fec authored by Matthew Landauer's avatar Matthew Landauer
Browse files

Handle variations in floating point precision between ruby versions

parent d55fe527
No related branches found
No related tags found
No related merge requests found
...@@ -2,19 +2,10 @@ require 'test_helper' ...@@ -2,19 +2,10 @@ require 'test_helper'
class NearTest < Test::Unit::TestCase class NearTest < Test::Unit::TestCase
def test_near_scope_options def test_near_scope_options_without_sqlite_includes_bounding_box_condition
result = Event.near_scope_options(1.0, 2.0, 5) result = Event.near_scope_options(1.0, 2.0, 5)
expected = {
:select =>
"test_table_name.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((1.0 - test_table_name.latitude) * PI() / 180 / 2), 2) + COS(1.0 * PI() / 180) * COS(test_table_name.latitude * PI() / 180) * POWER(SIN((2.0 - test_table_name.longitude) * PI() / 180 / 2), 2))) AS distance, CAST(DEGREES(ATAN2( RADIANS(test_table_name.longitude - 2.0), RADIANS(test_table_name.latitude - 1.0))) + 360 AS decimal) % 360 AS bearing",
:conditions =>
[
"test_table_name.latitude BETWEEN 0.927634108444576 AND 1.072365891555424 AND test_table_name.longitude BETWEEN 1.9276230850898697 AND 2.07237691491013 AND 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((1.0 - test_table_name.latitude) * PI() / 180 / 2), 2) + COS(1.0 * PI() / 180) * COS(test_table_name.latitude * PI() / 180) * POWER(SIN((2.0 - test_table_name.longitude) * PI() / 180 / 2), 2))) <= ?",
5
],
:order => "distance ASC"
}
assert_equal expected, result assert_match /test_table_name.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND test_table_name.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /,
result[:conditions][0]
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment