standalone: Add output_range and tests
This commit is contained in:
parent
2cfb7a7e10
commit
25d2de67f7
|
@ -44,6 +44,18 @@ void output_float64(double x) {
|
|||
}
|
||||
}
|
||||
|
||||
void output_range(int32_t range[3]) {
|
||||
printf("range(");
|
||||
if (range[0] != 0) {
|
||||
printf("%d, ", range[0]);
|
||||
}
|
||||
printf("%d", range[1]);
|
||||
if (range[2] != 1) {
|
||||
printf(", %d", range[2]);
|
||||
}
|
||||
puts(")");
|
||||
}
|
||||
|
||||
void output_asciiart(int32_t x) {
|
||||
static const char *chars = " .,-:;i+hHM$*#@ ";
|
||||
if (x < 0) {
|
||||
|
|
|
@ -22,6 +22,10 @@ def output_uint64(x: uint64):
|
|||
def output_float64(x: float):
|
||||
...
|
||||
|
||||
@extern
|
||||
def output_range(x: range):
|
||||
...
|
||||
|
||||
@extern
|
||||
def output_int32_list(x: list[int32]):
|
||||
...
|
||||
|
@ -63,6 +67,15 @@ def test_output_float64():
|
|||
output_float64(16.25)
|
||||
output_float64(-16.25)
|
||||
|
||||
def test_output_range():
|
||||
r = range(1, 100, 5)
|
||||
output_int32(r.start)
|
||||
output_int32(r.stop)
|
||||
output_int32(r.step)
|
||||
output_range(range(10))
|
||||
output_range(range(1, 10))
|
||||
output_range(range(1, 10, 2))
|
||||
|
||||
def test_output_asciiart():
|
||||
for i in range(17):
|
||||
output_asciiart(i)
|
||||
|
@ -82,6 +95,7 @@ def run() -> int32:
|
|||
test_output_uint32()
|
||||
test_output_uint64()
|
||||
test_output_float64()
|
||||
test_output_range()
|
||||
test_output_asciiart()
|
||||
test_output_int32_list()
|
||||
test_output_str_family()
|
||||
|
|
Loading…
Reference in New Issue