Commit 6e608081 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Updating and clarifying comments on tests

parent 3b64e214
......@@ -16,7 +16,6 @@
(hash-map :host (key %)
:time (apply + (map :time (val %)))
:icon (:icon (first (val %))))))
(into {})))
......
......@@ -270,7 +270,7 @@
(doseq [other (dissoc result id)]
(is (= (val other) (get (:site-times test-db) (key other))) "Other items should have remained untouched"))
;; Let's make sure we did not break anything while adding an ignore parameter
;; Let's make sure we did not break anything while adding an ignore-set parameter
(is (= result (data/track-site-time (:site-times test-db) tab 3 ts
:ignore-set #{"localhost" "newtab"}))
"The result should be the same even if we pass an ignore-set")))
......@@ -297,11 +297,11 @@
(doseq [other (dissoc result id)]
(is (= (val other) (get (:site-times test-db) (key other))) "Other items should have remained untouched"))
;; Then, let's make sure we did not break anything while adding an ignore parameter
;; Then, let's make sure we did not break anything while adding an ignore-set parameter
(is (= result
(data/track-site-time (:site-times test-db) tab 9 ts
:ignore-set #{"localhost" "somedomain.com"})))))
:ignore-set #{"localhost" "somedomain.com"}))
"The result should be the same even if we pass an ignore-set")))
(testing "Add zero time should not result on any changes"
......@@ -319,7 +319,7 @@
(is (= result (:site-times test-db)))
(is (nil? item))))
(testing "Add time from an invalid tab does not change the databse"
(testing "Add time for an invalid tab does not change the databse"
(let [tab {}
ts 1445964037920
result (data/track-site-time (:site-times test-db)
......@@ -352,7 +352,6 @@
147 (:time item)))))
(deftest test-clean-up-by-time
(testing "Clean up date and minimum time are respected"
(let [min-date 1446028215913
......@@ -413,7 +412,6 @@
(is (= 4 (count result))))))
(deftest test-accumulate-site-times
(testing "Accumulate site times creates a total but doesn't add favicons"
(is (= (into {} (map #(vector (key %) (assoc (val %) :icon nil))
......@@ -440,18 +438,17 @@
:time 4
:ts 1446051494575
:title "New York spot price Gold..."}}
acc (data/accumulate-site-times data)]
;; There should be no empty hostnames
; There should be no empty hostnames
; We check (get acc 0) because the result is indexed by the host-key,
; which returns 0 on nil or empty.
(is (nil? (get acc 0)))
;; Let' verify we got the right data
;; Let's verify we got the right data
(is (= {971841386 {:time 39, :icon nil, :host "numergent.com"},
-915908674 {:time 4, :icon nil, :host "www.kitco.com"}}
acc)))))
(deftest test-accumulate-after-clean-up
(testing "We get a value accumulation per site time after clean up"
(let [min-date 1446114615912
......
......@@ -112,7 +112,7 @@
(assoc :time (quot (:time in-v2) 1000))
(rename-keys {:icon :icon}))
)))
;; Test recurrent migration
;; Test applying all possible migrations iteratively
(is (= v3 (migrations/migrate-to-latest base-data)) "Migrating all the way to the latest should yield the same v2 data")
(is (= v3 (migrations/migrate-to-latest v1)) "Migrating all the way to the latest should yield the same v2 data")
(is (not= base-data (migrations/migrate-to-latest base-data)) "Migration loop should have returned a different data set")
......
(ns relevance.test.order
(:require [cljs.test :refer-macros [deftest testing is are]]
[relevance.data :as data]
[relevance.order :as order]
[relevance.utils :as utils]))
(deftest empty-test
(is (= 1 1)))
(deftest test-time-score
; A score for an unknown URL with no tab index is zero
......@@ -39,15 +36,15 @@
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A page inherits its site's score even if it's unknown
; A page inherits its site's score even if the page is unknown
(is (= 987 (order/time-score {:url "http://apple.com/mac"}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
{(utils/host-key "google.com") {:time 123}
(utils/host-key "apple.com") {:time 987}}
{})))
; A page inherits its site's score even if it's unknown, but substracts the index so
; that they are placed at the end.
; A page inherits its site's score even if the page is unknown, but
; substracts the index so that they are placed at the end.
(is (= 975 (order/time-score {:url "http://apple.com/mac" :index 12}
{(utils/url-key "http://google.com") {:time 291}
(utils/url-key "http://google.com/somepage") {:time 345}}
......@@ -82,6 +79,7 @@
(utils/host-key "apple.com") {:time 987}}
{}))))
(deftest test-score-tabs
(let [url-times {(utils/url-key "http://google.com") {:time 2910}
(utils/url-key "http://google.com/somepage") {:time 345}
......@@ -173,16 +171,5 @@
url-times
site-times
{})))
)
)
(ns relevance.test.utils
(:require [cljs.test :refer-macros [deftest testing is are]]
[relevance.utils :as utils]
))
[relevance.utils :as utils]))
(deftest test-key-from-url
......@@ -16,16 +15,16 @@
"Key should disregard trailing hashtags")
(is (= (utils/url-key "https://LOCALHOST")
(utils/url-key "https://localhost"))
"Key is not case-sensitive")
"Key should not consider the domain case-sensitive")
(is (= (utils/url-key "https://LOCALHOST/someUrl#hash")
(hash-string "localhost/someUrl"))
"Our hash calculations are consistent with hash-string")
"Our hash calculations should be consistent with hash-string")
(is (not= (utils/url-key "https://localhost?q=v")
(utils/url-key "https://localhost?q="))
"Key should respect query strings")
(is (not= (utils/url-key "https://localhost.com/path")
(utils/url-key "https://localhost.com/Path"))
"Path is case-sensitive")
"url-key should consider the path case-sensitive")
;; Let's confirm we actually return a consistent integer for some known values
(are [k url] (= k (utils/url-key url))
-20650657 "https://LOCALHOST/someUrl#hash"
......@@ -41,6 +40,7 @@
-847465478 "file:///Users/ricardo/Sources/user.html"
))
(deftest test-host-key
(are [k url] (= k (utils/host-key url))
-702889725 "www.google.com"
......@@ -49,8 +49,8 @@
-292940973 "www.numergent.com"
0 ""
0 " "
0 nil)
)
0 nil))
(deftest test-time-display
(are [time label] (= (utils/time-display time) label)
......@@ -74,13 +74,13 @@
248996 "2d 21h"
))
(deftest test-host
(deftest test-hostname
(are [url name] (= (utils/hostname url) name)
"https://www.google.com/some?q=v" "www.google.com"
"https://www.Google.com/some?q=v" "www.google.com"
"https://WWW.GOOGLE.COM/some?q=v" "www.google.com"
"http://WWW.GOOGLE.COM/some?q=v" "www.google.com"
"https://GOOGLE.COM:443/some?q=v" "google.com"
"https://GOOGLE.COM:443/some?q=v" "google.com" ; host would have included the port
"https://GOOGLE.COM:3000/some?q=v" "google.com" ; host would have included the port
"http://numergent.com/tag/khroma" "numergent.com"
"about:blank" ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment