<commit_before>(ns cmr.umm.test.generators.granule
  "Provides clojure.test.check generators for use in testing other projects."
  (:require [clojure.test.check.generators :as gen]
            [cmr.common.test.test-check-ext :as ext-gen :refer [optional]]
            [cmr.umm.test.generators.collection :as c]
            [cmr.umm.test.generators.granule.temporal :as gt]
            [cmr.umm.test.generators.collection.product-specific-attribute :as psa]
            [cmr.umm.test.generators.granule.orbit-calculated-spatial-domain :as ocsd]
            [cmr.umm.granule :as g]))

;;; granule related
(def granule-urs
  (ext-gen/string-ascii 1 80))

(def coll-refs-w-entry-title
  (ext-gen/model-gen g/collection-ref c/entry-titles))

(def coll-refs-w-short-name-version
  (ext-gen/model-gen g/collection-ref c/short-names c/version-ids))

(def coll-refs
  (gen/one-of [coll-refs-w-entry-title coll-refs-w-short-name-version]))

(def proj-refs
  (gen/vector (ext-gen/string-ascii 1 80)))

(def product-specific-attribute-refs
  (ext-gen/model-gen g/->ProductSpecificAttributeRef psa/names (gen/vector psa/string-values 1 3)))



(def data-granules
  (ext-gen/model-gen
    g/map->DataGranule
    (gen/hash-map :producer-gran-id (ext-gen/optional (ext-gen/string-ascii 1 128))
                  :day-night (gen/elements ["DAY" "NIGHT" "BOTH" "UNSPECIFIED"])
                  :production-date-time ext-gen/date-time)))

(def granules
  (ext-gen/model-gen
    g/map->UmmGranule
    (gen/hash-map
      :granule-ur granule-urs
      :collection-ref coll-refs
      :data-granule (ext-gen/optional data-granules)
      :temporal gt/temporal
      :orbit-calculated-spatial-domains (ext-gen/nil-if-empty (gen/vector ocsd/orbit-calculated-spatial-domains 0 5))
      :project-refs (ext-gen/nil-if-empty proj-refs)
      :product-specific-attributes (ext-gen/nil-if-empty (gen/vector product-specific-attribute-refs 0 5))
      ;; TODO - cloud-cover needs to be optional - merge function not working. Empty CloudCover fails validation.
      :cloud-cover (gen/frequency [[7 (ext-gen/choose-double 0.0 100.0)] [3 (ext-gen/choose-double 0.0 1.0)]]))))

;; Generator that only returns collection ref with entry-title
;; DEPRECATED - this will go away in the future. Don't use it.
(def granules-entry-title
  (gen/fmap (fn [[granule-ur coll-ref]]
              (g/map->UmmGranule {:granule-ur granule-ur
                                  :collection-ref coll-ref}))
            (gen/tuple granule-urs coll-refs-w-entry-title)))<commit_msg>CMR-343: corrected cloud-cover as optional element behavior<commit_after>(ns cmr.umm.test.generators.granule
  "Provides clojure.test.check generators for use in testing other projects."
  (:require [clojure.test.check.generators :as gen]
            [cmr.common.test.test-check-ext :as ext-gen :refer [optional]]
            [cmr.umm.test.generators.collection :as c]
            [cmr.umm.test.generators.granule.temporal :as gt]
            [cmr.umm.test.generators.collection.product-specific-attribute :as psa]
            [cmr.umm.test.generators.granule.orbit-calculated-spatial-domain :as ocsd]
            [cmr.umm.granule :as g]))

;;; granule related
(def granule-urs
  (ext-gen/string-ascii 1 80))

(def coll-refs-w-entry-title
  (ext-gen/model-gen g/collection-ref c/entry-titles))

(def coll-refs-w-short-name-version
  (ext-gen/model-gen g/collection-ref c/short-names c/version-ids))

(def coll-refs
  (gen/one-of [coll-refs-w-entry-title coll-refs-w-short-name-version]))

(def proj-refs
  (gen/vector (ext-gen/string-ascii 1 80)))

(def product-specific-attribute-refs
  (ext-gen/model-gen g/->ProductSpecificAttributeRef psa/names (gen/vector psa/string-values 1 3)))


(def data-granules
  (ext-gen/model-gen
    g/map->DataGranule
    (gen/hash-map :producer-gran-id (ext-gen/optional (ext-gen/string-ascii 1 128))
                  :day-night (gen/elements ["DAY" "NIGHT" "BOTH" "UNSPECIFIED"])
                  :production-date-time ext-gen/date-time)))

(def cloud-cover-elems
  (ext-gen/optional  (gen/frequency [[7 (ext-gen/choose-double 0.0 100.0)] [3 (ext-gen/choose-double 0.0 1.0)]])))

(def granules
  (ext-gen/model-gen
    g/map->UmmGranule
    (gen/hash-map
      :granule-ur granule-urs
      :collection-ref coll-refs
      :data-granule (ext-gen/optional data-granules)
      :temporal gt/temporal
      :orbit-calculated-spatial-domains (ext-gen/nil-if-empty (gen/vector ocsd/orbit-calculated-spatial-domains 0 5))
      :project-refs (ext-gen/nil-if-empty proj-refs)
      :product-specific-attributes (ext-gen/nil-if-empty (gen/vector product-specific-attribute-refs 0 5))
      :cloud-cover cloud-cover-elems)))

;; Generator that only returns collection ref with entry-title
;; DEPRECATED - this will go away in the future. Don't use it.
(def granules-entry-title
  (gen/fmap (fn [[granule-ur coll-ref]]
              (g/map->UmmGranule {:granule-ur granule-ur
                                  :collection-ref coll-ref}))
            (gen/tuple granule-urs coll-refs-w-entry-title)))
{'fraction_non_alphanumeric': 0.14477848101265822, 'fraction_numerical': 0.011669303797468354, 'mean_word_length': 2.8603053435114503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7645856', 'n_tokens_mistral': 1911, 'n_tokens_neox': 1746, 'n_words': 349}