<commit_before>(ns no.knowit.clojure-functional.product-repository
  (:use [clojure.test])
  (:import no.knowit.java_functional.product.Product)
  (:import [org.joda.time LocalDate]))

; Production code

; Use filter and provide your own function. Remember how you call a native Java method?
(defn product-is-available [local-date product-coll]
  (filter
    #(.isAvailable %1 local-date) product-coll))

; Write a recursive version not using filter. This is a bit advanced. Possible solutions include
; loop recur, conj and if. Remember to always terminate the recurring, or you will get infinite recursion.
(defn product-is-available-recur [local-date product-coll]
  (loop [cl product-coll result []]
    (if-let [h (first cl)]
      (recur (rest cl)
        (conj result
          (if (.isAvailable h local-date) h [])))
      result)))

; Define which function you want to test here
(def product-func product-is-available)

; Test code
(deftest empty_list_when_no_products
  (is (= (product-func (LocalDate.) []))))

(deftest product_available_when_matching_date
  (let [today (new LocalDate)
        product (new Product "Cool product" today today)]
    (is (not-empty (product-func today [product])))
    (is (.contains (product-func today [product]) product))))

(deftest empty_list_when_no_products_matching_date
  (let [today (new LocalDate)
        yesterday (.minusDays today 1)
        product (new Product "Cool product" yesterday yesterday)]
    (is (empty (product-func today [product])))))

(deftest find_discontinued_products
  (let [yesterday (.minusDays (new LocalDate) 1)
        product (new Product "Cool product" yesterday yesterday)]
    (is (not-empty (product-func yesterday [product])))))

(run-tests)<commit_msg>Actually testing the filtering...<commit_after>(ns no.knowit.clojure-functional.product-repository
  (:use [clojure.test])
  (:import no.knowit.java_functional.product.Product)
  (:import [org.joda.time LocalDate]))

; Production code

; Use filter and provide your own function. Remember how you call a native Java method?
(defn product-is-available [local-date product-coll]
  (filter
    #(.isAvailable %1 local-date) product-coll))

; Write a recursive version not using filter. This is a bit advanced. Possible solutions include
; loop recur, conj and if. Remember to always terminate the recurring, or you will get infinite recursion.
(defn product-is-available-recur [local-date product-coll]
  (loop [cl product-coll result []]
    (if-let [h (first cl)]
      (recur (rest cl)
        (conj result
          (if (.isAvailable h local-date) h [])))
      result)))

; Define which function you want to test here
(def product-func product-is-available)

; Test code
(deftest empty_list_when_no_products
  (is (= (product-func (LocalDate.) []))))

(deftest product_available_when_matching_date
  (let [today (new LocalDate)
        product (new Product "Cool product" today today)]
    (is (not-empty (product-func today [product])))
    (is (.contains (product-func today [product]) product))))

(deftest empty_list_when_no_products_matching_date
  (let [today (new LocalDate)
        yesterday (.minusDays today 1)
        product (new Product "Cool product" yesterday yesterday)]
    (is (empty? (product-func today [product])))))

(deftest filter-one-products-matching-date
  (let [today (new LocalDate)
        yesterday (.minusDays today 1)
        product-one (new Product "Cool product" yesterday yesterday)
        product-two (new Product "Todays product" today today)]
    (is (= 1 (count (product-func today [product-one product-two]))))))

(deftest find_discontinued_products
  (let [yesterday (.minusDays (new LocalDate) 1)
        product (new Product "Cool product" yesterday yesterday)]
    (is (not-empty (product-func yesterday [product])))))

(run-tests)
{'fraction_non_alphanumeric': 0.11698508243915205, 'fraction_numerical': 0.002093692750588851, 'mean_word_length': 3.963636363636364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380612', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1122, 'n_words': 383}