Changeset 37269 in project


Ignore:
Timestamp:
02/21/19 08:17:09 (4 weeks ago)
Author:
iraikov
Message:

srfi-4-comprehensions: added tests

Location:
release/5/srfi-4-comprehensions/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/srfi-4-comprehensions/trunk/srfi-4-comprehensions.egg

    r37268 r37269  
    55 (license "SRFI")
    66 (dependencies srfi-42)
     7 (test-dependencies srfi-1 test)
    78 (category data)
    89 (author "Will Farr")
  • release/5/srfi-4-comprehensions/trunk/srfi-4-comprehensions.scm

    r37268 r37269  
    3333(module srfi-4-comprehensions
    3434  (:s8vector :u8vector :s16vector :u16vector :s32vector
    35    :u32vector :f64vector :f32vector
    36    :s64vector :u64vector
     35   :u32vector :f64vector :f32vector :s64vector :u64vector
    3736           
    3837   s8vector-ec u8vector-ec s16vector-ec u16vector-ec s32vector-ec
    39    u32vector-ec f64vector-ec f32vector-ec
     38   u32vector-ec s64vector-ec u64vector-ec f64vector-ec f32vector-ec
    4039           
    4140   s8vector-of-length-ec u8vector-of-length-ec s16vector-of-length-ec
    42    u16vector-of-length-ec s32vector-of-length-ec
    43    u32vector-of-length-ec
     41   u16vector-of-length-ec s32vector-of-length-ec u32vector-of-length-ec
     42   s64vector-of-length-ec u64vector-of-length-ec
    4443   f64vector-of-length-ec f32vector-of-length-ec)
    4544
  • release/5/srfi-4-comprehensions/trunk/tests/run.scm

    r37268 r37269  
    1 (import scheme (chicken base) srfi-42 srfi-4-comprehensions)
     1(import scheme (chicken base) srfi-1 srfi-4 srfi-42 srfi-4-comprehensions test)
    22
    3 (define n 19)
     3(define n 20)
    44
    5 (print (s32vector-ec (: i 0 (+ 1 n)) i))
     5(define xlst (list-tabulate n (lambda (x) x)))
    66
    7 (print (f32vector-ec (: i 0. (+ 1 n)) (* 0.1 i)))
     7(define (to-4-dp f)
     8  (/ (round (* f 10000)) 10000))
     9
     10(define (=4 n1 n2)
     11  (= (to-4-dp n1) (to-4-dp n2)))
     12
     13(test-group "SRFI-4 vector comprehension"
     14           
     15            (test (list->f64vector xlst) (f64vector-ec (: i 0 n) i) )
     16            (test (list->f32vector xlst) (f32vector-ec (: i 0 n) i) )
     17;            (test (list->s64vector xlst) (s64vector-ec (: i 0 n) i) )
     18            (test (list->u64vector xlst) (u64vector-ec (: i 0 n) i) )
     19            (test (list->s32vector xlst) (s32vector-ec (: i 0 n) i) )
     20            (test (list->u32vector xlst) (u32vector-ec (: i 0 n) i) )
     21            (test (list->s16vector xlst) (s16vector-ec (: i 0 n) i) )
     22            (test (list->u16vector xlst) (u16vector-ec (: i 0 n) i) )
     23            (test (list->s8vector xlst) (s8vector-ec (: i 0 n) i) )
     24            (test (list->u8vector xlst) (u8vector-ec (: i 0 n) i) )
     25
     26            )
    827
    928
    10 (let ((v (f64vector-ec (: i 0. (+ 1 n)) (* 0.5 i))))
    11   (print v)
    12   (print (fold-ec 0. (:f64vector x (index i) v) x (lambda (x ax) (+ ax (* x x)))))
    13   )
     29
     30(test-group "SRFI-4 vector fold comprehension"
     31           
     32            (let ((v (f64vector-ec (: i 0. n) (* 0.5 i))))
     33             
     34              (test-assert (=4 617.5 (fold-ec 0. (:f64vector x (index i) v) x (lambda (x ax) (+ ax (* x x)))))))
     35
     36            (let ((v (f32vector-ec (: i 0. n) (* 0.5 i))))
     37             
     38              (test-assert (=4 617.5 (fold-ec 0. (:f32vector x (index i) v) x (lambda (x ax) (+ ax (* x x))))))
     39                   
     40  ))
Note: See TracChangeset for help on using the changeset viewer.