<commit_before>(export list-test)

(import
  :gerbil/gambit/exceptions
  :std/error :std/misc/list :std/test)

(def (error-with-message? message)
  (lambda (e)
    (and (error-exception? e) (equal? (error-exception-message e) message))))

(def (copy-list lst) (foldr cons '() lst))

(def list-test
  (test-suite "test suite for std/misc/list"
    (test-case "test length=?"
      (check-equal? (length=? '(1 2 3) '(a b c)) #t)
      (check-equal? (length=? '(1 2 3) '(a b c d)) #f)
      (check-equal? (length=? '(1 2 3 4) '(a b c)) #f)
      (check-equal? (length=? '(1 2 3) '(a b c . d)) #t)
      (check-equal? (length=? '(1 2 3 . 4) '(a b c)) #t))
    (test-case "test length<?"
      (check-equal? (length<? '(1 2 3) '(a b c d)) #t)
      (check-equal? (length<? '(1 2 3 . 4) '(a b c d)) #t)
      (check-equal? (length<? '(1 2 3) '(a b c)) #f)
      (check-equal? (length<? '(1 2 3 4) '(a b c)) #f)
      (check-equal? (length<? '(1 2 3) '(a b c . d)) #f))
    (test-case "test length=n?"
      (check-equal? (length=n? '(1 2 3) 4) #f)
      (check-equal? (length=n? '(1 2 3) 3) #t)
      (check-equal? (length=n? '(1 2 3) 2) #f)
      (check-equal? (length=n? '(1 2 3) 3.14159) #f)
      (check-equal? (length=n? '(1 2 3) 3.0) #t)
      (check-equal? (length=n? '(1 2 3) 2.5) #f)
      (check-equal? (length=n? '(1 2 3 4) 3) #f)
      (check-equal? (length=n? '(1 2 3 . 4) 3) #t)
      (check-equal? (length=n? '(1 2 3 . 4) 4) #f)
      (check-equal? (length=n? '(1 2 3 . 4) 3.5) #f)
      (check-equal? (length=n? '(1 2 3) -4) #f)
      (check-equal? (length=n? '(1 2 3) 6.022e23) #f)
      (check-equal? (length=n? '(1 2 3) 2+3i) #f)
      (check-exception (length=n? '(1 2 3) 'foo) (error-with-message? "not a number")))
    (test-case "test length<=n?"
      (check-equal? (length<=n? '(1 2 3) 4) #t)
      (check-equal? (length<=n? '(1 2 3) 3) #t)
      (check-equal? (length<=n? '(1 2 3) 2) #f)
      (check-equal? (length<=n? '(1 2 3) 3.14159) #t)
      (check-equal? (length<=n? '(1 2 3) 3.0) #t)
      (check-equal? (length<=n? '(1 2 3) 2.5) #f)
      (check-equal? (length<=n? '(1 2 3 4) 3) #f)
      (check-equal? (length<=n? '(1 2 3 . 4) 4) #t)
      (check-equal? (length<=n? '(1 2 3 . 4) 3) #t)
      (check-equal? (length<=n? '(1 2 3 . 4) 2) #f)
      (check-equal? (length<=n? '(1 2 3) -4) #f)
      (check-equal? (length<=n? '(1 2 3) 6.022e23) #t)
      (check-exception (length<=n? '(1 2 3) 2+3i) (error-with-message? "not a real number"))
      (check-exception (length<=n? '(1 2 3) 'foo) (error-with-message? "not a real number")))
    (test-case "test length<n?"
      (check-equal? (length<n? '(1 2 3) 4) #t)
      (check-equal? (length<n? '(1 2 3) 3) #f)
      (check-equal? (length<n? '(1 2 3) 2) #f)
      (check-equal? (length<n? '(1 2 3) 3.14159) #t)
      (check-equal? (length<n? '(1 2 3) 3.0) #f)
      (check-equal? (length<n? '(1 2 3) 2.5) #f)
      (check-equal? (length<n? '(1 2 3 4) 3) #f)
      (check-equal? (length<n? '(1 2 3 . 4) 4) #t)
      (check-equal? (length<n? '(1 2 3 . 4) 3) #f)
      (check-equal? (length<n? '(1 2 3 . 4) 2) #f)
      (check-equal? (length<n? '(1 2 3) -4) #f)
      (check-equal? (length<n? '(1 2 3) 6.022e23) #t)
      (check-exception (length<n? '(1 2 3) 2+3i) (error-with-message? "not a real number"))
      (check-exception (length<n? '(1 2 3) 'foo) (error-with-message? "not a real number")))
    (test-case "test call-with-list-builder"
      (check-equal?
       (call-with-list-builder
        (lambda (put! _)
          (put! 1) (put! 2) (put! 3)))
       '(1 2 3))
      (check-equal?
       (call-with-list-builder
        (lambda (put! get-list-so-far)
          (put! 1)
          (put! 2)
          (put! (copy-list (get-list-so-far)))
          (put! 3)))
       '(1 2 (1 2) 3)))))
<commit_msg>Add tests for snoc and append1<commit_after>(export list-test)

(import
  :gerbil/gambit/exceptions
  :std/error :std/misc/list :std/test)

(def (error-with-message? message)
  (lambda (e)
    (and (error-exception? e) (equal? (error-exception-message e) message))))

(def (copy-list lst) (foldr cons '() lst))

(def list-test
  (test-suite "test suite for std/misc/list"
    (test-case "test length=?"
      (check-equal? (length=? '(1 2 3) '(a b c)) #t)
      (check-equal? (length=? '(1 2 3) '(a b c d)) #f)
      (check-equal? (length=? '(1 2 3 4) '(a b c)) #f)
      (check-equal? (length=? '(1 2 3) '(a b c . d)) #t)
      (check-equal? (length=? '(1 2 3 . 4) '(a b c)) #t))
    (test-case "test length<?"
      (check-equal? (length<? '(1 2 3) '(a b c d)) #t)
      (check-equal? (length<? '(1 2 3 . 4) '(a b c d)) #t)
      (check-equal? (length<? '(1 2 3) '(a b c)) #f)
      (check-equal? (length<? '(1 2 3 4) '(a b c)) #f)
      (check-equal? (length<? '(1 2 3) '(a b c . d)) #f))
    (test-case "test length=n?"
      (check-equal? (length=n? '(1 2 3) 4) #f)
      (check-equal? (length=n? '(1 2 3) 3) #t)
      (check-equal? (length=n? '(1 2 3) 2) #f)
      (check-equal? (length=n? '(1 2 3) 3.14159) #f)
      (check-equal? (length=n? '(1 2 3) 3.0) #t)
      (check-equal? (length=n? '(1 2 3) 2.5) #f)
      (check-equal? (length=n? '(1 2 3 4) 3) #f)
      (check-equal? (length=n? '(1 2 3 . 4) 3) #t)
      (check-equal? (length=n? '(1 2 3 . 4) 4) #f)
      (check-equal? (length=n? '(1 2 3 . 4) 3.5) #f)
      (check-equal? (length=n? '(1 2 3) -4) #f)
      (check-equal? (length=n? '(1 2 3) 6.022e23) #f)
      (check-equal? (length=n? '(1 2 3) 2+3i) #f)
      (check-exception (length=n? '(1 2 3) 'foo) (error-with-message? "not a number")))
    (test-case "test length<=n?"
      (check-equal? (length<=n? '(1 2 3) 4) #t)
      (check-equal? (length<=n? '(1 2 3) 3) #t)
      (check-equal? (length<=n? '(1 2 3) 2) #f)
      (check-equal? (length<=n? '(1 2 3) 3.14159) #t)
      (check-equal? (length<=n? '(1 2 3) 3.0) #t)
      (check-equal? (length<=n? '(1 2 3) 2.5) #f)
      (check-equal? (length<=n? '(1 2 3 4) 3) #f)
      (check-equal? (length<=n? '(1 2 3 . 4) 4) #t)
      (check-equal? (length<=n? '(1 2 3 . 4) 3) #t)
      (check-equal? (length<=n? '(1 2 3 . 4) 2) #f)
      (check-equal? (length<=n? '(1 2 3) -4) #f)
      (check-equal? (length<=n? '(1 2 3) 6.022e23) #t)
      (check-exception (length<=n? '(1 2 3) 2+3i) (error-with-message? "not a real number"))
      (check-exception (length<=n? '(1 2 3) 'foo) (error-with-message? "not a real number")))
    (test-case "test length<n?"
      (check-equal? (length<n? '(1 2 3) 4) #t)
      (check-equal? (length<n? '(1 2 3) 3) #f)
      (check-equal? (length<n? '(1 2 3) 2) #f)
      (check-equal? (length<n? '(1 2 3) 3.14159) #t)
      (check-equal? (length<n? '(1 2 3) 3.0) #f)
      (check-equal? (length<n? '(1 2 3) 2.5) #f)
      (check-equal? (length<n? '(1 2 3 4) 3) #f)
      (check-equal? (length<n? '(1 2 3 . 4) 4) #t)
      (check-equal? (length<n? '(1 2 3 . 4) 3) #f)
      (check-equal? (length<n? '(1 2 3 . 4) 2) #f)
      (check-equal? (length<n? '(1 2 3) -4) #f)
      (check-equal? (length<n? '(1 2 3) 6.022e23) #t)
      (check-exception (length<n? '(1 2 3) 2+3i) (error-with-message? "not a real number"))
      (check-exception (length<n? '(1 2 3) 'foo) (error-with-message? "not a real number")))
    (test-case "test call-with-list-builder"
      (check-equal?
       (call-with-list-builder
        (lambda (put! _)
          (put! 1) (put! 2) (put! 3)))
       '(1 2 3))
      (check-equal?
       (call-with-list-builder
        (lambda (put! get-list-so-far)
          (put! 1)
          (put! 2)
          (put! (copy-list (get-list-so-far)))
          (put! 3)))
       '(1 2 (1 2) 3)))
    (test-case "test snoc"
      (check-equal? (snoc 3 []) [3])
      (check-equal? (snoc 1 [3 2]) [3 2 1]))
    (test-case "test append1"
      (check-equal? (append1 [] 3) [3])
      (check-equal? (append1 [3 2] 1) [3 2 1]))))
{'fraction_non_alphanumeric': 0.23741836342681522, 'fraction_numerical': 0.07043155333589449, 'mean_word_length': 2.4000870700914234, 'pattern_counts': {'":': 0, '<': 75, '<?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': '208869', 'n_tokens_mistral': 3876, 'n_tokens_neox': 3487, 'n_words': 1047}