; Follow-up — trending objects/actors by recent activity. (feed-test name got expected)

; window (50,100]: X@60,X@70 (a), Y@80 (b), Z@90 (c); W@40 is too old
(define
  S
  (feed/stream
    (list
      (feed/activity "a" "post" "X" 60 (list))
      (feed/activity "a" "post" "X" 70 (list))
      (feed/activity "b" "post" "Y" 80 (list))
      (feed/activity "c" "post" "Z" 90 (list))
      (feed/activity "d" "post" "W" 40 (list)))))

; ---------- trending objects ----------

(feed-test
  "trending count (3 in window)"
  (len (feed/trending S 100 50 10))
  3)
(feed-test
  "trending top object"
  (get
    (nth (feed/trending S 100 50 10) 0)
    :object)
  "X")
(feed-test
  "trending top count"
  (get
    (nth (feed/trending S 100 50 10) 0)
    :count)
  2)
(feed-test
  "trending order (count desc, key asc tiebreak)"
  (map
    (fn (e) (get e :object))
    (feed/trending S 100 50 10))
  (list "X" "Y" "Z"))
(feed-test
  "trending top-2"
  (map
    (fn (e) (get e :object))
    (feed/trending S 100 50 2))
  (list "X" "Y"))
(feed-test
  "old object W excluded"
  (feed/-elem?
    "W"
    (map
      (fn (e) (get e :object))
      (feed/trending S 100 50 10)))
  false)
(feed-test
  "narrow window keeps only newest"
  (map
    (fn (e) (get e :object))
    (feed/trending S 100 15 10))
  (list "Z"))
(feed-test
  "empty window -> nothing"
  (feed/trending S 100 5 10)
  (list))

; ---------- trending actors ----------

(feed-test
  "trending actor top"
  (get
    (nth (feed/trending-actors S 100 50 10) 0)
    :actor)
  "a")
(feed-test
  "trending actor count"
  (get
    (nth (feed/trending-actors S 100 50 10) 0)
    :count)
  2)
(feed-test
  "trending actors order"
  (map
    (fn (e) (get e :actor))
    (feed/trending-actors S 100 50 10))
  (list "a" "b" "c"))
