|
| 1 | +require_relative "helper" |
| 2 | + |
| 3 | +class TestCommandsGeo < Test::Unit::TestCase |
| 4 | + include Helper::Client |
| 5 | + |
| 6 | + def setup |
| 7 | + super |
| 8 | + |
| 9 | + added_items_count = r.geoadd("Sicily", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania") |
| 10 | + assert_equal 2, added_items_count |
| 11 | + end |
| 12 | + |
| 13 | + def test_georadius_with_sort |
| 14 | + nearest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'asc') |
| 15 | + assert_equal %w(Catania Palermo), nearest_cities |
| 16 | + |
| 17 | + farthest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'desc') |
| 18 | + assert_equal %w(Palermo Catania), farthest_cities |
| 19 | + end |
| 20 | + |
| 21 | + def test_georadius_with_count |
| 22 | + city = r.georadius("Sicily", 15, 37, 200, 'km', count: 1) |
| 23 | + assert_equal %w(Catania), city |
| 24 | + end |
| 25 | + |
| 26 | + def test_georadius_with_options_count_sort |
| 27 | + city = r.georadius("Sicily", 15, 37, 200, 'km', sort: :desc, options: :WITHDIST, count: 1) |
| 28 | + assert_equal [["Palermo", "190.4424"]], city |
| 29 | + end |
| 30 | + |
| 31 | + def test_georadiusbymember_with_sort |
| 32 | + nearest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'asc') |
| 33 | + assert_equal %w(Catania Palermo), nearest_cities |
| 34 | + |
| 35 | + farthest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'desc') |
| 36 | + assert_equal %w(Palermo Catania), farthest_cities |
| 37 | + end |
| 38 | + |
| 39 | + def test_georadiusbymember_with_count |
| 40 | + city = r.georadiusbymember("Sicily", "Catania", 200, 'km', count: 1) |
| 41 | + assert_equal %w(Catania), city |
| 42 | + end |
| 43 | + |
| 44 | + def test_georadiusbymember_with_options_count_sort |
| 45 | + city = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: :desc, options: :WITHDIST, count: 1) |
| 46 | + assert_equal [["Palermo", "166.2742"]], city |
| 47 | + end |
| 48 | + |
| 49 | + def test_geopos |
| 50 | + location = r.geopos("Sicily", "Catania") |
| 51 | + assert_equal [["15.08726745843887329", "37.50266842333162032"]], location |
| 52 | + |
| 53 | + locations = r.geopos("Sicily", ["Palermo", "Catania"]) |
| 54 | + assert_equal [["13.36138933897018433", "38.11555639549629859"], ["15.08726745843887329", "37.50266842333162032"]], locations |
| 55 | + end |
| 56 | + |
| 57 | + def test_geopos_nonexistant_location |
| 58 | + location = r.geopos("Sicily", "Rome") |
| 59 | + assert_equal [nil], location |
| 60 | + |
| 61 | + locations = r.geopos("Sicily", ["Rome", "Catania"]) |
| 62 | + assert_equal [nil, ["15.08726745843887329", "37.50266842333162032"]], locations |
| 63 | + end |
| 64 | + |
| 65 | + def test_geodist |
| 66 | + distination_in_meters = r.geodist("Sicily", "Palermo", "Catania") |
| 67 | + assert_equal "166274.1516", distination_in_meters |
| 68 | + |
| 69 | + distination_in_feet = r.geodist("Sicily", "Palermo", "Catania", 'ft') |
| 70 | + assert_equal "545518.8700", distination_in_feet |
| 71 | + end |
| 72 | + |
| 73 | + def test_geodist_with_nonexistant_location |
| 74 | + distination = r.geodist("Sicily", "Palermo", "Rome") |
| 75 | + assert_equal nil, distination |
| 76 | + end |
| 77 | + |
| 78 | + def test_geohash |
| 79 | + geohash = r.geohash("Sicily", "Palermo") |
| 80 | + assert_equal ["sqc8b49rny0"], geohash |
| 81 | + |
| 82 | + geohashes = r.geohash("Sicily", ["Palermo", "Catania"]) |
| 83 | + assert_equal %w(sqc8b49rny0 sqdtr74hyu0), geohashes |
| 84 | + end |
| 85 | + |
| 86 | + def test_geohash_with_nonexistant_location |
| 87 | + geohashes = r.geohash("Sicily", ["Palermo", "Rome"]) |
| 88 | + assert_equal ["sqc8b49rny0", nil], geohashes |
| 89 | + end |
| 90 | +end |
0 commit comments