ocaml: phase 6 Char predicates (+7 tests, 461 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s
Char.is_digit / is_alpha / is_alnum / is_whitespace / is_upper / is_lower / is_space — all written in OCaml using Char.code + ASCII range checks.
This commit is contained in:
@@ -377,6 +377,16 @@
|
||||
let chr n = _char_chr n
|
||||
let lowercase_ascii c = _string_lower c
|
||||
let uppercase_ascii c = _string_upper c
|
||||
let is_digit c =
|
||||
let n = _char_code c in n >= 48 && n <= 57
|
||||
let is_lower c =
|
||||
let n = _char_code c in n >= 97 && n <= 122
|
||||
let is_upper c =
|
||||
let n = _char_code c in n >= 65 && n <= 90
|
||||
let is_alpha c = is_lower c || is_upper c
|
||||
let is_alnum c = is_alpha c || is_digit c
|
||||
let is_whitespace c =
|
||||
c = \" \" || c = \"\\t\" || c = \"\\n\" || c = \"\\r\"
|
||||
end ;;
|
||||
|
||||
module Int = struct
|
||||
|
||||
@@ -1124,6 +1124,22 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 4202)
|
||||
(eval "(ocaml-type-of-program \"let rec map f xs = match xs with | [] -> [] | h :: t -> f h :: map f t and length lst = match lst with | [] -> 0 | _ :: t -> 1 + length t;; map\")")
|
||||
|
||||
;; ── Char predicate helpers ────────────────────────────────────
|
||||
(epoch 4300)
|
||||
(eval "(ocaml-run \"Char.is_digit \\\"5\\\"\")")
|
||||
(epoch 4301)
|
||||
(eval "(ocaml-run \"Char.is_digit \\\"x\\\"\")")
|
||||
(epoch 4302)
|
||||
(eval "(ocaml-run \"Char.is_alpha \\\"x\\\"\")")
|
||||
(epoch 4303)
|
||||
(eval "(ocaml-run \"Char.is_alnum \\\"5\\\"\")")
|
||||
(epoch 4304)
|
||||
(eval "(ocaml-run \"Char.is_whitespace \\\" \\\"\")")
|
||||
(epoch 4305)
|
||||
(eval "(ocaml-run \"Char.is_upper \\\"A\\\"\")")
|
||||
(epoch 4306)
|
||||
(eval "(ocaml-run \"Char.is_lower \\\"a\\\"\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1780,6 +1796,15 @@ check 4200 "let-mut x+y" '"Int"'
|
||||
check 4201 "let-rec-mut even 10" '"Bool"'
|
||||
check 4202 "let-rec-mut map+length" 'list -> '
|
||||
|
||||
# ── Char predicates ────────────────────────────────────────────
|
||||
check 4300 "Char.is_digit 5" 'true'
|
||||
check 4301 "Char.is_digit x" 'false'
|
||||
check 4302 "Char.is_alpha x" 'true'
|
||||
check 4303 "Char.is_alnum 5" 'true'
|
||||
check 4304 "Char.is_whitespace ' '" 'true'
|
||||
check 4305 "Char.is_upper A" 'true'
|
||||
check 4306 "Char.is_lower a" 'true'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user