Cleaning up tests. This is just embarrassing.

This commit is contained in:
John Wiseman 2020-10-12 11:48:23 -07:00
parent c3c384d030
commit c72d24dcbf

View File

@ -26,22 +26,21 @@
"dst" "14.6", "reg" "HL7634", "altt" "0", "cou" "South Korea", "dst" "14.6", "reg" "HL7634", "altt" "0", "cou" "South Korea",
"postime" "1575488288571", "galt" "139", "mlat" "0", "spd" "10.5", "postime" "1575488288571", "galt" "139", "mlat" "0", "spd" "10.5",
"sqk" "", "talt" "", "wtc" "3", "alt" "100", "lon" "-118.416438", "sqk" "", "talt" "", "wtc" "3", "alt" "100", "lon" "-118.416438",
"opicao" "AAR", "interested" "0", "trak" "264.4", "type" "A388", "opicao" "AAR", "interested" "0", "trak" "264.4",
"trkh" "0", "icao" "71BE34", "lat" "33.937908", "vsit" "1", "trkh" "0", "icao" "71BE34", "lat" "33.937908", "vsit" "1",
"tisb" "0", "vsi" "0", "sat" "0"}] "tisb" "0", "vsi" "0", "sat" "0"}
(is (= (advisorycircular/parse-adsbexchange-ac-element ac) r (advisorycircular/parse-adsbexchange-ac-element ac)]
{:icao "71BE34" (is (= (:icao r) "71BE34"))
:registration "HL7634" (is (= (:registration r) "HL7634"))
:callsign nil (is (= (:callsign r) nil))
:type "A388" (is (a= (:lon r) -118.416438))
:lon -118.416438 (is (a= (:lat r) 33.937908))
:lat 33.937908 (is (a= (:alt r) 100))
:alt 100 (is (a= (:speed r) 10.5))
:speed 10.5 (is (= (:squawk r) nil))
:squawk nil (is (not (:military? r)))
:military? false (is (not (:mlat? r)))
:mlat? false (is (a= (:postime r) 1575488288571))))
:postime 1575488288571}))))
(deftest prune-history (deftest prune-history
@ -72,7 +71,7 @@
:history [{:time 1000 :id 0} :history [{:time 1000 :id 0}
{:time 2000 :id 1} {:time 2000 :id 1}
{:time 3000 :id 2} {:time 3000 :id 2}
{:time 3500 :lat 1 :lon 1}]} {:time 3500 :lat 1 :lon 1 :alt nil :gnd? nil}]}
"1" :anything})))) "1" :anything}))))
(testing "Adding a new record" (testing "Adding a new record"
(let [db {"0" {:icao "0" (let [db {"0" {:icao "0"
@ -100,13 +99,93 @@
:lat 1 :lat 1
:lon 1 :lon 1
:postime 3500 :postime 3500
:history [{:time 3500 :lat 1 :lon 1}]}}))))) :history [{:time 3500 :lat 1 :lon 1 :alt nil :gnd? nil}]}})))))
(deftest expand-template (deftest expand-template
(let [data {:locality "Palmdale", :continent "North America", :military? true, :alt 3850, :speed "209", :normalized-curviness 14.768651250300287, :accuracy "centroid", :country_a "USA", :continent_gid "whosonfirst:continent:102191575", :name "Palmdale", :squawk "5330", :icao "AE1482", :county_a "LO", :county "Los Angeles County", :source "whosonfirst", :gid "whosonfirst:locality:85923493", :curviness 1269.8089810739468, :locality_gid "whosonfirst:locality:85923493", :region "California", :militaryicao "AE1482", :region_a "CA", :nearbydistance 8.167, :callsign "RAIDR49", :layer "locality", :mlat? false, :country_gid "whosonfirst:country:85633793", :label "Palmdale, CA, USA", :id "85923493", :lon -118.00375, :region_gid "whosonfirst:region:85688637", :lat 34.661074, :militaryregistration "166765", :county_gid "whosonfirst:county:102086957", :started-circling-time 1576266715691, :distance 6.855, :source_id "85923493", :registration "166765", :confidence 0.5, :country "United States", :postime 1576266689756, :nearbylandmark "Living Faith Foursquare Church"}] (let [data {:locality "Palmdale"
:continent "North America"
:military? true
:alt 3850
:speed "209"
:normalized-curviness 14.768651250300287
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "Palmdale"
:squawk "5330"
:icao "AE1482"
:county_a "LO"
:county "Los Angeles County"
:source "whosonfirst"
:gid "whosonfirst:locality:85923493"
:curviness 1269.8089810739468
:locality_gid "whosonfirst:locality:85923493"
:region "California"
:militaryicao "AE1482"
:region_a "CA"
:nearbydistance 8.167
:callsign "RAIDR49"
:layer "locality"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "Palmdale, CA, USA"
:id "85923493"
:lon -118.00375
:region_gid "whosonfirst:region:85688637"
:lat 34.661074
:militaryregistration "166765"
:county_gid "whosonfirst:county:102086957"
:started-circling-time 1576266715691
:distance 6.855
:source_id "85923493"
:registration "166765"
:confidence 0.5
:country "United States"
:postime 1576266689756
:nearbylandmark "Living Faith Foursquare Church"}]
(is (strmatch #"military" (-> (advisorycircular/expand-template data) :text)))) (is (strmatch #"military" (-> (advisorycircular/expand-template data) :text))))
(let [data {:locality "Palmdale", :continent "North America", :military? true, :alt 3200, :speed "161", :normalized-curviness 15.783422690487765, :accuracy "centroid", :country_a "USA", :continent_gid "whosonfirst:continent:102191575", :name "Palmdale", :squawk "5330", :icao "AE1482", :county_a "LO", :county "Los Angeles County", :source "whosonfirst", :gid "whosonfirst:locality:85923493", :curviness 1098.803548060181, :locality_gid "whosonfirst:locality:85923493", :region "California", :militaryicao "AE1482", :region_a "CA", :nearbydistance 7.828, :callsign "RAIDR49", :layer "locality", :mlat? false, :country_gid "whosonfirst:country:85633793", :label "Palmdale, CA, USA", :id "85923493", :lon -118.049183, :region_gid "whosonfirst:region:85688637", :lat 34.649808, :militaryregistration "166765", :county_gid "whosonfirst:county:102086957", :started-circling-time 1576267564959, :distance 6.336, :source_id "85923493", :registration "166765", :confidence 0.5, :country "United States", :postime 1576267555709, :nearbylandmark "Living Faith Foursquare Church"}] (let [data {:locality "Palmdale"
:continent "North America"
:military? true
:alt 3200
:speed "161"
:normalized-curviness 15.783422690487765
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "Palmdale"
:squawk "5330"
:icao "AE1482"
:county_a "LO"
:county "Los Angeles County"
:source "whosonfirst"
:gid "whosonfirst:locality:85923493"
:curviness 1098.803548060181
:locality_gid "whosonfirst:locality:85923493"
:region "California"
:militaryicao "AE1482"
:region_a "CA"
:nearbydistance 7.828
:callsign "RAIDR49"
:layer "locality"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "Palmdale, CA, USA"
:id "85923493"
:lon -118.049183
:region_gid "whosonfirst:region:85688637"
:lat 34.649808
:militaryregistration "166765"
:county_gid "whosonfirst:county:102086957"
:started-circling-time 1576267564959
:distance 6.336
:source_id "85923493"
:registration "166765"
:confidence 0.5
:country "United States"
:postime 1576267555709
:nearbylandmark "Living Faith Foursquare Church"}]
(is (strmatch #"military" (-> (advisorycircular/expand-template data) :text)))) (is (strmatch #"military" (-> (advisorycircular/expand-template data) :text))))
(testing "a vs. an for type" (testing "a vs. an for type"
(let [data {:registration "TEST" :icao "123" :type "Airbus 380" :locality "Test City"}] (let [data {:registration "TEST" :icao "123" :type "Airbus 380" :locality "Test City"}]
@ -115,14 +194,14 @@
(is (strmatch #"a Yoyo" (:text (advisorycircular/expand-template data))))))) (is (strmatch #"a Yoyo" (:text (advisorycircular/expand-template data)))))))
(deftest merge-adsbx-sqb (deftest merge-adsbx-db-rec
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration "N1"}
{:registration "N2" :type "B52"}) {:registration "N2" :type "B52"})
{:registration "N1", :type "B52"})) {:registration "N1", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration nil} (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration nil}
{:registration "N2" :type "B52"}) {:registration "N2" :type "B52"})
{:registration "N2", :type "B52"})) {:registration "N2", :type "B52"}))
(is (= (advisorycircular/merge-adsbx-sqb {:registration "N1"} (is (= (advisorycircular/merge-adsbx-aircraft-db-rec {:registration "N1"}
{:registration "N2" :type nil}) {:registration "N2" :type nil})
{:registration "N1", :type nil}))) {:registration "N1", :type nil})))
@ -160,7 +239,6 @@
desc (advisorycircular/generate-description ac sqb reverse nearby)] desc (advisorycircular/generate-description ac sqb reverse nearby)]
(is (strmatch #"N80NT" desc)) (is (strmatch #"N80NT" desc))
(is (strmatch #"a Eurocopter Squirrel AS 350 B2" desc)) (is (strmatch #"a Eurocopter Squirrel AS 350 B2" desc))
(is (strmatch #"callsign N80NT" desc))
(is (strmatch #"Silver Lake.*Los Angeles" desc)) (is (strmatch #"Silver Lake.*Los Angeles" desc))
(is (strmatch #"1300 feet" desc)) (is (strmatch #"1300 feet" desc))
(is (strmatch #"speed 83 MPH" desc)) (is (strmatch #"speed 83 MPH" desc))
@ -183,68 +261,67 @@
(def r2508-data1 (def r2508-data1
[{:continent "North America" [{:accuracy "point"
:accuracy "point" :confidence 0.5
:country_a "USA" :continent "North America"
:continent_gid "whosonfirst:continent:102191575" :continent_gid "whosonfirst:continent:102191575"
:name "Haystack Butte" :country "United States"
:county_a "SA" :country_a "USA"
:county "San Bernardino County"
:source "openstreetmap"
:gid "openstreetmap:venue:node/358808120"
:region "California"
:region_a "CA"
:layer "venue"
:country_gid "whosonfirst:country:85633793" :country_gid "whosonfirst:country:85633793"
:label "Haystack Butte, San Bernardino County, CA, USA" :county "San Bernardino County"
:id "node/358808120" :county_a "SA"
:region_gid "whosonfirst:region:85688637"
:county_gid "whosonfirst:county:102085395" :county_gid "whosonfirst:county:102085395"
:distance 4.261 :distance 4.261
:source_id "node/358808120" :gid "openstreetmap:venue:node/358808120"
:confidence 0.5 :id "node/358808120"
:country "United States"} :label "Haystack Butte, San Bernardino County, CA, USA"
{:continent "North America" :layer "venue"
:military? :name "Haystack Butte"
true
:alt 5825
:speed "226"
:normalized-curviness 14.188938867970446
:accuracy "centroid"
:country_a "USA"
:continent_gid "whosonfirst:continent:102191575"
:name "San Bernardino County"
:squawk "0026"
:icao "AE264F"
:county_a "SA"
:county "San Bernardino County"
:type "Beechcraft C-12C Huron"
:source "whosonfirst"
:gid "whosonfirst:county:102085395"
:curviness 1463.4205557421808
:region "California" :region "California"
:militaryicao "AE264F"
:region_a "CA" :region_a "CA"
:nearbydistance "2.65"
:callsign "COBRA02"
:layer "county"
:mlat? false
:country_gid "whosonfirst:country:85633793"
:label "San Bernardino County, CA, USA"
:id "102085395"
:lon -117.629528
:region_gid "whosonfirst:region:85688637" :region_gid "whosonfirst:region:85688637"
:lat 34.884804 :source "openstreetmap"
:militaryregistration "73-1215?" :source_id "node/358808120"}
:county_gid "whosonfirst:county:102085395" {:accuracy "centroid"
:started-circling-time 1581098223891 :alt 5825
:distance 132.69 :callsign "COBRA02"
:source_id "102085395"
:registration "73-1215?"
:confidence 0.5 :confidence 0.5
:continent "North America"
:continent_gid "whosonfirst:continent:102191575"
:country "United States", :country "United States",
:country_a "USA"
:country_gid "whosonfirst:country:85633793"
:county "San Bernardino County"
:county_a "SA"
:county_gid "whosonfirst:county:102085395"
:curviness 1463.4205557421808
:distance 132.69
:gid "whosonfirst:county:102085395"
:icao "AE264F"
:id "102085395"
:label "San Bernardino County, CA, USA"
:lat 34.884804
:layer "county"
:lon -117.629528
:military? true
:militaryicao "AE264F"
:militaryregistration "73-1215?"
:mlat? false
:name "San Bernardino County"
:nearbydistance "2.65"
:nearbylandmark "Haystack Butte"
:normalized-curviness 14.188938867970446
:postime 1581098213228 :postime 1581098213228
:nearbylandmark "Haystack Butte"} :region "California"
:region_a "CA"
:region_gid "whosonfirst:region:85688637"
:registration "73-1215?"
:source "whosonfirst"
:source_id "102085395"
:speed "226"
:squawk "0026"
:started-circling-time 1581098223891
:type "Beechcraft C-12C Huron"}
{:continent "North America" {:continent "North America"
:military? true :military? true
:alt 14000 :alt 14000
@ -289,13 +366,18 @@
(deftest r2508-description (deftest r2508-description
(testing "R-2508 generation" (testing "R-2508 generation"
(is (= (:text (advisorycircular/expand-template (nth r2508-data1 0))) (is (= (advisorycircular/expand-template (nth r2508-data1 0))
"73-1215?, a military Beechcraft C-12C Huron, (callsign COBRA02) is circling over San Bernardino County at 5825 feet, speed 226 MPH, squawking 0026, 2.65 miles from Haystack Butte #73-1215? https://tar1090.adsbexchange.com/?icao=AE264F&zoom=13")) nil))
(is (= (:text (advisorycircular/expand-template (nth r2508-data1 1))) (is (= (:text (advisorycircular/expand-template (nth r2508-data1 1)))
"73-1215?, a military Beechcraft C-12C Huron, (callsign COBRA02) is circling over San Bernardino County at 5825 feet, speed 226 MPH, squawking 0026, 2.65 miles from Haystack Butte #73-1215? https://tar1090.adsbexchange.com/?icao=AE264F&zoom=13")) (str "73-1215?, a military Beechcraft C-12C Huron, (callsign COBRA02)"
" is circling over San Bernardino County at 5825 feet, speed 226"
" MPH, squawking 0026, 2.65 miles from Haystack Butte #73_1215?"
" https://globe.adsbexchange.com/?icao=AE264F&zoom=13")))
(is (= (:text (advisorycircular/expand-template (nth r2508-data1 2))) (is (= (:text (advisorycircular/expand-template (nth r2508-data1 2)))
"76-0166, a military Beechcraft C-12C Huron, (callsign COBRA37) is circling over Kern County at 14000 feet, speed 139 MPH, squawking 0006, 1.93 miles from Russell Mine #76-0166 https://tar1090.adsbexchange.com/?icao=AE2651&zoom=13"))) (str "76-0166, a military Beechcraft C-12C Huron, (callsign COBRA37)"
" is circling over Kern County at 14000 feet, speed 139 MPH,"
" squawking 0006, 1.93 miles from Russell Mine #76_0166"
" https://globe.adsbexchange.com/?icao=AE2651&zoom=13"))))
(testing "foo" (testing "foo"
(let [ac {:military? false :alt 1300 :speed 72.1 :squawk "1200" (let [ac {:military? false :alt 1300 :speed 72.1 :squawk "1200"
:icao "AAE0C2" :type nil, :callsign "N80NT", :registration nil} :icao "AAE0C2" :type nil, :callsign "N80NT", :registration nil}
@ -305,7 +387,6 @@
desc (advisorycircular/generate-description ac sqb reverse nearby)] desc (advisorycircular/generate-description ac sqb reverse nearby)]
(is (strmatch #"N80NT" desc)) (is (strmatch #"N80NT" desc))
(is (strmatch #"a Eurocopter Squirrel AS 350 B2" desc)) (is (strmatch #"a Eurocopter Squirrel AS 350 B2" desc))
(is (strmatch #"callsign N80NT" desc))
(is (strmatch #"Silver Lake.*Los Angeles" desc)) (is (strmatch #"Silver Lake.*Los Angeles" desc))
(is (strmatch #"1300 feet" desc)) (is (strmatch #"1300 feet" desc))
(is (strmatch #"speed 83 MPH" desc)) (is (strmatch #"speed 83 MPH" desc))