about summary refs log tree commit diff stats
path: root/mu.arc.t
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-17 15:41:24 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-17 15:41:24 -0800
commit877b4fae0436bdf22e7c0f911ce8f7030038a04c (patch)
treead84b545ec8d1c1575edcbdcd43075cce1e76967 /mu.arc.t
parenta1e8f8d8b41fa9f3ad381ebc7868900a266545c0 (diff)
downloadmu-877b4fae0436bdf22e7c0f911ce8f7030038a04c.tar.gz
576 - helper for printing integers
This requires creating a new data structure called buffer, because
strings are too inefficient for appending to, and we need to know how
long they need to be before we clear them.

But I'm not gonna bother to write tests for all the new primitives I
just introduced, because that's not expedient.

One test for mu is how nicely it handles situations like this without
requiring perfect test hygiene. In this case, I can imagine tools that
will extract tests for a particular function out of all known tests.
Especially if it's a pure function that should be easy. Then just show
each test to the programmer and ask him to give it a reasonable name.
Diffstat (limited to 'mu.arc.t')
-rw-r--r--mu.arc.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/mu.arc.t b/mu.arc.t
index 1b378c5a..dcb38e0f 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -4034,6 +4034,41 @@
             (~memory-contains-array (memory* (+ base 4)) "c"))
     (prn "F - 'split' cuts string at two delimiters")))
 
+(reset)
+(new-trace "integer-to-decimal-string")
+(add-code
+  '((function main [
+      (1:string-address/raw <- integer-to-decimal-string 34:literal)
+    ])))
+;? (set dump-trace*)
+;? (= dump-trace* (obj whitelist '("run")))
+(run 'main)
+(let base memory*.1
+  (when (~memory-contains-array base "34")
+    (prn "F - converting integer to decimal string")))
+
+(reset)
+(new-trace "integer-to-decimal-string-zero")
+(add-code
+  '((function main [
+      (1:string-address/raw <- integer-to-decimal-string 0:literal)
+    ])))
+(run 'main)
+(let base memory*.1
+  (when (~memory-contains-array base "0")
+    (prn "F - converting zero to decimal string")))
+
+(reset)
+(new-trace "integer-to-decimal-string-negative")
+(add-code
+  '((function main [
+      (1:string-address/raw <- integer-to-decimal-string -237:literal)
+    ])))
+(run 'main)
+(let base memory*.1
+  (when (~memory-contains-array base "-237")
+    (prn "F - converting negative integer to decimal string")))
+
 )  ; section 100 for string utilities
 
 (reset)