<commit_before>#lang scheme/base

(require tests/eli-tester lazy)

;; tests for lazy language constructs
;; add tests as needed

(provide test-take)

(define (test-take)
  (define test-lst1 '(1 2 3))
  (test (! (take "nonnum" test-lst1)) =error> "take: expects type <non-negative exact integer> as 1st argument, given: \"nonnum\"; other arguments were: (1 2 3)"
        (! (take -1 test-lst1)) =error> "take: expects type <non-negative exact integer> as 1st argument, given: -1; other arguments were: (1 2 3)"
        (! (take -1 "nonlist")) =error> "take: expects type <non-negative exact integer> as 1st argument, given: -1; other arguments were: \"nonlist\""
        (! (take 0 "nonlist")) => '() ; this is how Racket's take behaves
        (! (take 1 "nonlist")) =error> "take: not a proper list: \"nonlist\""
        (! (take 0 null)) => '()
        (! (take 0 test-lst1)) => '()  ; test for push#22080
        (! (car (take 1 test-lst1))) => 1
        (! (cdr (take 1 test-lst1))) => '()
        (! (first (take 2 test-lst1))) => 1
        (! (second (take 2 test-lst1))) => 2
        (! (cddr (take 2 test-lst1))) => '()
        (! (first (take 4 test-lst1))) => 1
        (! (second (take 4 test-lst1))) => 2
        (! (third (take 4 test-lst1))) => 3
        (! (fourth (take 4 test-lst1))) =error> "take: index 4 too large for input list"))

; not working, only get 1 test passed
#;(define (langimpl-tests)
  (test (test-take)))<commit_msg>add test for lazy take bug fix -- invariant being incorrectly tested on unforced arg<commit_after>#lang scheme/base

(require tests/eli-tester lazy)

;; tests for lazy language constructs
;; add tests as needed

(provide test-take)

(define (test-take)
  (define test-lst1 '(1 2 3))
  (test (! (take "nonnum" test-lst1)) =error> "take: expects type <non-negative exact integer> as 1st argument, given: \"nonnum\"; other arguments were: (1 2 3)"
        (! (take -1 test-lst1)) =error> "take: expects type <non-negative exact integer> as 1st argument, given: -1; other arguments were: (1 2 3)"
        (! (take -1 "nonlist")) =error> "take: expects type <non-negative exact integer> as 1st argument, given: -1; other arguments were: \"nonlist\""
        (! (take 0 "nonlist")) => '() ; this is how Racket's take behaves
        (! (take 1 "nonlist")) =error> "take: not a proper list: \"nonlist\""
        (! (take 0 null)) => '()
        (! (take 0 test-lst1)) => '()  ; test for push#22080
        (! (car (take 1 test-lst1))) => 1
        (! (cdr (take 1 test-lst1))) => '()
        (! (first (take 2 test-lst1))) => 1
        (! (second (take 2 test-lst1))) => 2
        (! (cddr (take 2 test-lst1))) => '()
        (! (first (take 4 test-lst1))) => 1
        (! (second (take 4 test-lst1))) => 2
        (! (third (take 4 test-lst1))) => 3
        (! (fourth (take 4 test-lst1))) =error> "take: index 4 too large for input list"
        (! (list-ref (take (car (list 1)) (list 2)) 0)) => 2
        ))

; not working, only get 1 test passed
#;(define (langimpl-tests)
  (test (test-take)))
{'fraction_non_alphanumeric': 0.182714426552744, 'fraction_numerical': 0.03746302990469931, 'mean_word_length': 2.8145363408521304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 42, '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': '2624813', 'n_tokens_mistral': 1077, 'n_tokens_neox': 995, 'n_words': 371}