<commit_before>(ns degasolv.resolver.search-strat-test
  (:require [clojure.test :refer :all]
            [degasolv.resolver :refer :all]
            [clojure.core.match :refer [match]]
            [serovers.core :refer [maven-vercmp]
             :rename {maven-vercmp cmp}])
  (:import [degasolv.resolver
            PackageInfo
            Requirement]))

(deftest ^:unit-tests basic-dfs
  (testing "Make sure ``the puzzle`` still works"
    (let [package-a
          (->package
           "a"
           1
           "a_loc1"
           [
            [(present "b")]
            [(present "c")]
            ]
           )
          package-b
          (->package
           "b"
           1
           "b_loc1"
           [
            [(present "d" #(>= (:version %) 1))]
            ]
           )
          package-c
          (->package
           "c"
           1
           "c_loc1"
           [
            [(present "d" #(< (:version %) 4))]
            ]
           )
          package-d1
          (->package
           "d"
           1
           "d_loc1"
           [
            [(present "e" #(.equals (:version %) 4))]
            ]
           )
          package-d2
          (->package
           "d"
           2
           "d_loc2"
           [
            [(present "e" #(.equals (:version %) 3))]
            ]
           )
          package-e4
          (->package
           "e"
           4
           "e_loc4"
           nil)
          package-e3
          (->package
           "3"
           3
           "e_loc3"
           nil)
          repo-info
          {"a" [package-a]
           "b" [package-b]
           "c" [package-c]
           "d" [package-d2 package-d1]
           "e" [package-e4 package-e3]}
          query
          (map-query repo-info)]
      (is (.equals [:successful #{package-a
                                  package-b
                                  package-c
                                  package-d2
                                  package-e3}]
                   (resolve-dependencies
                    [
                     [(present "a")]
                     ]
                    query
                    :search-strat :depth-first)))))
    (let [d
          {
           :id "d"
           :version "4.0.0"
           :location "http://example.com/repo/d-4.0.0.zip"
           }
          c
          {
           :id "c"
           :version "2.7.0"
           :location "http://example.com/repo/c-2.7.0.zip"
           }
          b
          {
           :id "b"
           :version "1.0.0"
           :location "http://example.com/repo/b-1.0.0.zip"
           :requirements
           [
            [
             {:status :present
              :id "d"
              }
             {:status :present
              :id "c"
              }
             ]
            ]
           }
          a
          {
           :id "a"
           :version "1.0.0"
           :location "http://example.com/repo/a-1.0.0.zip"
           :requirements
           [
            [
             {:status :present
              :id "b"
              }
             ]
            [
             {:status :present
              :id "c"
              }
             {:status :present
              :id "d"
              }
             ]
            ]
           }
          repo-info
          {
           "a"
           [
            a
            ]
           "b"
           [
            b
            ]
           "c"
           [
            c
            ]
           "d"
           [
            d
            ]
           }
          query (map-query repo-info)]
  (testing "order of resolution depending on search-strat - breadth first"
      (is (= [:successful
              #{c
                b
                a}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :breadth-first
              :compare cmp))))
  (testing "order of resolution depending on search-strat - depth first"
      (is (= [:successful
              #{d
                b
                a}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :depth-first
              :compare cmp)))))
  (let [e
        {
         :id "e"
         :version "7.0.0"
         :location "http://example.com/repo/3-7.0.0.zip"
         }
        d
        {
         :id "d"
         :version "4.0.0"
         :location "http://example.com/repo/d-4.0.0.zip"
         }
        c
        {
         :id "c"
         :version "2.7.0"
         :location "http://example.com/repo/c-2.7.0.zip"
         }
        b
        {
         :id "b"
         :version "1.0.0"
         :location "http://example.com/repo/b-1.0.0.zip"
         :requirements
         [
          [
           {:status :absent
            :id "d"
            }
           {:status :present
            :id "e"
            }
           ]
          ]
         }
        a
        {
         :id "a"
         :version "1.0.0"
         :location "http://example.com/repo/a-1.0.0.zip"
         :requirements
         [
          [
           {:status :present
            :id "b"
            }
           ]
          [
           {:status :present
            :id "d"
            }
           {:status :present
            :id "c"
            }
           ]
          ]
         }
        repo-info
        {
         "a"
         [
          a
          ]
         "b"
         [
          b
          ]
         "c"
         [
          c
          ]
         "d"
         [
          d
          ]
         "e"
         [
          e
          ]
         }
        query (map-query repo-info)]
  (testing "search strat: order of resolution: breadth first: absent"
      (is (= [:successful
              #{a
                b
                d
                e}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :breadth-first
              :compare cmp))))
  (testing "search strat: order of resolution: depth first: absent"
      (is (= [:successful
              #{a
                b
                c}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :depth-first
              :compare cmp))))))<commit_msg>MOAR on my quest to add bfs/dfs. Added a TODO.<commit_after>(ns degasolv.resolver.search-strat-test
  (:require [clojure.test :refer :all]
            [degasolv.resolver :refer :all]
            [clojure.core.match :refer [match]]
            [serovers.core :refer [maven-vercmp]
             :rename {maven-vercmp cmp}])
  (:import [degasolv.resolver
            PackageInfo
            Requirement]))

(deftest ^:unit-tests basic-dfs
  (testing "Make sure ``the puzzle`` still works"
    (let [package-a
          (->package
           "a"
           1
           "a_loc1"
           [
            [(present "b")]
            [(present "c")]
            ]
           )
          package-b
          (->package
           "b"
           1
           "b_loc1"
           [
            [(present "d" #(>= (:version %) 1))]
            ]
           )
          package-c
          (->package
           "c"
           1
           "c_loc1"
           [
            [(present "d" #(< (:version %) 4))]
            ]
           )
          package-d1
          (->package
           "d"
           1
           "d_loc1"
           [
            [(present "e" #(.equals (:version %) 4))]
            ]
           )
          package-d2
          (->package
           "d"
           2
           "d_loc2"
           [
            [(present "e" #(.equals (:version %) 3))]
            ]
           )
          package-e4
          (->package
           "e"
           4
           "e_loc4"
           nil)
          package-e3
          (->package
           "3"
           3
           "e_loc3"
           nil)
          repo-info
          {"a" [package-a]
           "b" [package-b]
           "c" [package-c]
           "d" [package-d2 package-d1]
           "e" [package-e4 package-e3]}
          query
          (map-query repo-info)]
      (is (.equals [:successful #{package-a
                                  package-b
                                  package-c
                                  package-d2
                                  package-e3}]
                   (resolve-dependencies
                    [
                     [(present "a")]
                     ]
                    query
                    :search-strat :depth-first)))))
    (let [d
          {
           :id "d"
           :version "4.0.0"
           :location "http://example.com/repo/d-4.0.0.zip"
           }
          c
          {
           :id "c"
           :version "2.7.0"
           :location "http://example.com/repo/c-2.7.0.zip"
           }
          b
          {
           :id "b"
           :version "1.0.0"
           :location "http://example.com/repo/b-1.0.0.zip"
           :requirements
           [
            [
             {:status :present
              :id "d"
              }
             {:status :present
              :id "c"
              }
             ]
            ]
           }
          a
          {
           :id "a"
           :version "1.0.0"
           :location "http://example.com/repo/a-1.0.0.zip"
           :requirements
           [
            [
             {:status :present
              :id "b"
              }
             ]
            [
             {:status :present
              :id "c"
              }
             {:status :present
              :id "d"
              }
             ]
            ]
           }
          repo-info
          {
           "a"
           [
            a
            ]
           "b"
           [
            b
            ]
           "c"
           [
            c
            ]
           "d"
           [
            d
            ]
           }
          query (map-query repo-info)]
  (testing "order of resolution depending on search-strat - breadth first"
      (is (= [:successful
              #{c
                b
                a}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :breadth-first
              :compare cmp))))
  (testing "order of resolution depending on search-strat - depth first"
      (is (= [:successful
              #{d
                b
                a}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :depth-first
              :compare cmp)))))
  (let [e
        {
         :id "e"
         :version "7.0.0"
         :location "http://example.com/repo/3-7.0.0.zip"
         }
        d
        {
         :id "d"
         :version "4.0.0"
         :location "http://example.com/repo/d-4.0.0.zip"
         }
        c
        {
         :id "c"
         :version "2.7.0"
         :location "http://example.com/repo/c-2.7.0.zip"
         }
        b
        {
         :id "b"
         :version "1.0.0"
         :location "http://example.com/repo/b-1.0.0.zip"
         :requirements
         [
          [
           {:status :absent
            :id "d"
            }
           {:status :present
            :id "e"
            }
           ]
          ]
         }
        a
        {
         :id "a"
         :version "1.0.0"
         :location "http://example.com/repo/a-1.0.0.zip"
         :requirements
         [
          [
           {:status :present
            :id "b"
            }
           ]
          [
           {:status :present
            :id "d"
            }
           {:status :present
            :id "c"
            }
           ]
          ]
         }
        repo-info
        {
         "a"
         [
          a
          ]
         "b"
         [
          b
          ]
         "c"
         [
          c
          ]
         "d"
         [
          d
          ]
         "e"
         [
          e
          ]
         }
        query (map-query repo-info)]
  (testing "search strat: order of resolution: breadth first: absent"
      (is (= [:successful
              #{a
                b
                d
                e}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :breadth-first
              :compare cmp))))
  (testing "search strat: order of resolution: depth first: absent"
      (is (= [:successful
              #{a
                b
                c}]
             (resolve-dependencies
              [[{:status :present :id "a"}]]
              query
              :conflict-strat :prioritized
              :search-strat :depth-first
              :compare cmp))))))
;; TODO: Add test using conflict strat as prioritized
{'fraction_non_alphanumeric': 0.11918933172606043, 'fraction_numerical': 0.012657274165599338, 'mean_word_length': 0.7198756154444157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2484664', 'n_tokens_mistral': 3868, 'n_tokens_neox': 3775, 'n_words': 740}