Add more test fixture files

This commit is contained in:
Joshua Peek
2011-09-06 15:39:22 -05:00
parent 0239a59248
commit f9df8685b4
21 changed files with 778 additions and 1 deletions

114
test/fixtures/BCR2000.sc vendored Normal file
View File

@@ -0,0 +1,114 @@
BCR2000 {
var controls,
controlBuses,
rangedControlBuses,
responders
;
*new {
^super.new.init;
}
init {
controls = Dictionary.new(108);
controlBuses = Dictionary.new(108);
rangedControlBuses = Dictionary.new(108);
this.createCCResponders;
}
createCCResponders {
responders = Array.fill(108, {|i|
CCResponder({|src, chan, num, val|
[src, chan, num, val].postln;
// Write to controls
controls.put(i + 1, val);
// Write to bus (converted to scalar 0..1)
controlBuses.put(i + 1, Bus.control(Server.default));
controlBuses.at(i + 1).value = val / 127;
},
// Adjust values as/if needed
nil, // src
nil, // chan
nil, // num
nil // value
)
});
}
// Value from BCR
at {arg controlNum;
^controls.at(controlNum)
}
// Convert to 0..1
scalarAt {arg controlNum;
^controls.at(controlNum) / 127
}
// Get a bus
busAt {arg controlNum;
^controlBuses.at(controlNum)
}
/*
busRangeAt(arg controlNum, lo, hi;
if (rangedControlBuses.at(controlNum).isNil, {
rangedControlBuses.put(controlNum, Bus.control(Server.default))
});
// Left to right order of operations
//rangedControlBuses.put(
bus.value = hi - lo * controls.at(controlNum) + lo;
^bus
}
*/
}
/* Scratch
Dictionary
b = BCR2000();
b.at(4);
b.scalarAt(4);
b.controls[5].get;
throw
z = Dictionary.new(2);
z.at(\1);
Array.fill(10, {|i| i.postln;})
(2 + 3).asSymbol;
SynthDef(\x, {
arg amp = 0.01,
freq = 1200,
modDepth = 0.7,
modFreq = 2
;
var
carrier,
modulator
;
modulator = SinOsc.ar(modFreq, mul: modDepth);
carrier = Saw.ar(freq, add: modulator, mul: amp);
Out.ar([0,1], carrier)
}).store;
x = Synth(\x);
x.set(\modDepth, 1);
x.set(\modFreq, 64);
x.map(\modFreq, b.busAt(
ControlSpec
*/

82
test/fixtures/Foo.ml vendored Normal file
View File

@@ -0,0 +1,82 @@
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(*
@author Louis Gesbert
**)
type 'a t = ('a -> unit) -> unit
module Ops = struct
let (@>) f k = f k
let (|>) x k = k x
end
open Ops
module List = struct
let rec map f l k = match l with
| [] -> [] |> k
| hd::tl -> f hd @> fun hd -> map f tl @> fun tl -> hd::tl |> k
let rec fold f acc l k = match l with
| [] -> acc |> k
| hd::tl -> f acc hd @> fun acc -> fold f acc tl @> k
end
module Option = struct
let rec map f opt k = match opt with
| None -> None |> k
| Some x -> f x @> fun x -> Some x |> k
end
module Lazy = struct
type 'a t = {
push : (unit -> unit) -> unit;
mutable value : 'a option;
mutable waiters : ('a -> unit) list;
cps : ('a -> unit) -> unit;
}
let make push cps = {
push = push;
value = None;
waiters = [];
cps = cps;
}
let force l k =
match l.value with
| Some x -> x |> k
| None when l.waiters != [] ->
l.waiters <- k::l.waiters
| None ->
l.waiters <- k::l.waiters;
l.cps
@> function x ->
Base.List.iter (fun k -> l.push (fun () -> k x)) l.waiters;
l.value <- Some x;
l.waiters <- []
let get_state cps = cps.value
let lazy_from_val x = {
push = (fun _ -> ());
value = Some x;
waiters = [];
cps = fun k -> k x;
}
end

27
test/fixtures/Foo.sig vendored Normal file
View File

@@ -0,0 +1,27 @@
signature LAZY_BASE =
sig
type 'a lazy
exception Undefined
val force: 'a lazy -> 'a
val delay: (unit -> 'a) -> 'a lazy
val undefined: 'a lazy
end
signature LAZY' =
sig
include LAZY_BASE
val isUndefined: 'a lazy -> bool
val inject : 'a -> 'a lazy
val toString: ('a -> string) -> 'a lazy -> string
val eq: ''a lazy * ''a lazy -> bool
val eqBy: ('a * 'a -> bool) -> 'a lazy * 'a lazy -> bool
val compare: ('a * 'a -> order) -> 'a lazy * 'a lazy -> order
val map: ('a -> 'b) -> 'a lazy -> 'b lazy
structure Ops:
sig
val ! : 'a lazy -> 'a (* force *)
val ? : 'a -> 'a lazy (* inject *)
end
end

75
test/fixtures/Foo.sml vendored Normal file
View File

@@ -0,0 +1,75 @@
structure LazyBase:> LAZY_BASE =
struct
type 'a lazy = unit -> 'a
exception Undefined
fun delay f = f
fun force f = f()
val undefined = fn () => raise Undefined
end
structure LazyMemoBase:> LAZY_BASE =
struct
datatype 'a susp = NotYet of unit -> 'a
| Done of 'a
type 'a lazy = unit -> 'a susp ref
exception Undefined
fun delay f =
let
val r = ref (NotYet f)
in
fn () => r
end
fun force f =
case f() of
ref (Done x) => x
| r as ref (NotYet f') =>
let
val a = f'()
in
r := Done a
; a
end
val undefined = fn () => raise Undefined
end
functor LazyFn(B: LAZY_BASE): LAZY' =
struct
open B
fun inject x = delay (fn () => x)
fun isUndefined x =
(ignore (force x)
; false)
handle Undefined => true
fun toString f x = if isUndefined x then "_|_" else f (force x)
fun eqBy p (x,y) = p(force x,force y)
fun eq (x,y) = eqBy op= (x,y)
fun compare p (x,y) = p(force x,force y)
structure Ops =
struct
val ! = force
val ? = inject
end
fun map f x = delay (fn () => f (force x))
end
structure Lazy' = LazyFn(LazyBase)
structure LazyMemo = LazyFn(LazyMemoBase)

435
test/fixtures/asteroids.sps vendored Normal file
View File

@@ -0,0 +1,435 @@
(import (rnrs)
(only (surfage s1 lists) filter-map)
(gl)
(glut)
(dharmalab records define-record-type)
(dharmalab math basic)
(agave glu compat)
(agave geometry pt)
(agave glamour window)
(agave glamour misc)
(surfage s19 time)
(surfage s27 random-bits)
(surfage s42 eager-comprehensions))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; utilities
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (say . args)
(for-each display args)
(newline))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (gl-translate-pt p)
(glTranslated (pt-x p) (pt-y p) 0.0))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (radians x) (* x (/ pi 180)))
(define (degrees x) (* x (/ 180 pi)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (angle->pt a)
(pt (cos a)
(sin a)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (current-time-in-nanoseconds)
(let ((val (current-time)))
(+ (* (time-second val) 1000000000)
(time-nanosecond val))))
(define (current-time-in-seconds)
(/ (current-time-in-nanoseconds)
1000.0 ;; micro
1000.0 ;; milli
1000.0))
(define base-time (current-time-in-seconds))
(define (time-step) (- (current-time-in-seconds) base-time))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define score 0)
(define level 1)
(define ships 3)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; spaceship
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ spaceship
(fields (mutable pos)
(mutable vel)
(mutable theta)
(mutable force)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; particle
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ particle
(fields (mutable pos)
(mutable vel)
(mutable birth)
(mutable lifetime)
(mutable color)))
(define particles '())
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; bullet
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ bullet
(fields (mutable pos)
(mutable vel)
(mutable birth)))
(define bullets '())
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; asteroid
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ asteroid
(fields (mutable pos)
(mutable vel)
(mutable radius)))
(define number-of-starting-asteroids 4)
(define asteroids #f)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; bullet-pack
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-record-type++ bullet-pack
(fields (mutable pos)
(mutable vel)))
(define pack #f)
(is-bullet-pack pack)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(initialize-glut)
(window (size 800 400)
(title "Asteroids")
(reshape (width height)))
(random-source-randomize! default-random-source)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (pt-wrap p)
(pt (mod (pt-x p) width)
(mod (pt-y p) height)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define ship
(make-spaceship (pt (/ width 2.0) (/ height 2.0))
(pt 0.0 0.0)
0.0
0.0))
(is-spaceship ship)
(define ammo 0)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set! asteroids
(list-ec (: i number-of-starting-asteroids)
(make-asteroid (pt (inexact (random-integer width))
(inexact (random-integer height)))
(pt (inexact (+ -50 (random-integer 100)))
(inexact (+ -50 (random-integer 100))))
50.0)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set! pack (make-bullet-pack (pt (inexact (random-integer width))
(inexact (random-integer height)))
(pt (inexact (+ -50 (random-integer 100)))
(inexact (+ -50 (random-integer 100))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(buffered-display-procedure
(lambda ()
(background 0.0)
;; ship
(glColor3f 0.0 1.0 0.0)
(gl-matrix-excursion
(gl-translate-pt ship.pos)
(glRotated 90.0 0.0 1.0 0.0)
(glRotated (degrees ship.theta) -1.0 0.0 0.0)
(glutWireCone 10.0 30.0 5 5))
;; particles
(for-each
(lambda (par)
(let ((c (particle-color par)))
(glColor3f (vector-ref c 0)
(vector-ref c 1)
(vector-ref c 2)))
(gl-matrix-excursion
(gl-translate-pt (particle-pos par))
(glutWireSphere 2.0 5 5)))
particles)
;; bullets
(glColor3f 0.0 0.0 1.0)
(for-each
(lambda (bullet)
(gl-matrix-excursion
(gl-translate-pt (bullet-pos bullet))
(glutWireSphere 5.0 10 10)))
bullets)
;; asteroids
(glColor3f 1.0 0.0 0.0)
(for-each
(lambda (asteroid)
(gl-matrix-excursion
(gl-translate-pt (asteroid-pos asteroid))
(glutWireSphere (asteroid-radius asteroid) 10 10)))
asteroids)
;; bullet-pack
(glColor3f 0.0 0.0 1.0)
(gl-matrix-excursion
(gl-translate-pt pack.pos)
(glutWireCube 10.0))
))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define last-time (current-time-in-seconds))
(define dt 0)
(define (update-system)
(set! dt (- (current-time-in-seconds) last-time))
(set! last-time (current-time-in-seconds))
(ship.pos! (pt-wrap (pt+ ship.pos (pt*n ship.vel dt))))
(pack.pos! (pt-wrap (pt+ pack.pos (pt*n pack.vel dt))))
(set! particles
(filter-map
(lambda (par)
(is-particle par)
(cond ((> (- (current-time-in-seconds) par.birth) par.lifetime) #f)
(else (par.pos! (pt+ par.pos (pt*n par.vel dt)))
par)))
particles))
(set! bullets
(filter-map
(lambda (bullet)
(is-bullet bullet)
(cond ((> (- (current-time-in-seconds) bullet.birth) 2.0) #f)
(else (bullet.pos! (pt+ bullet.pos (pt*n bullet.vel dt)))
bullet)))
bullets))
(set! asteroids
(filter-map
(lambda (a)
(is-asteroid a)
(a.pos! (pt-wrap (pt+ a.pos (pt*n a.vel dt))))
(if (< a.radius 10.0) #f a))
asteroids))
;; bullet asteroid contact
(for-each
(lambda (b)
(is-bullet b)
(for-each
(lambda (a)
(is-asteroid a)
(when (<= (pt-distance b.pos a.pos)
a.radius)
(begin (set! score (+ score 1))
(say "score: " score)
#f)
(set! asteroids
(append
(list-ec (: i 4)
(make-asteroid a.pos
(pt (+ -50.0 (random-integer 100))
(+ -50.0 (random-integer 100)))
(/ a.radius 2.0)))
asteroids))
(a.radius! 0.1)
(b.birth! 0.0)
(set! particles
(append (list-ec (: i 100)
(make-particle a.pos
(pt*n (angle->pt
(radians
(random-integer 360)))
(random-integer 100)
)
(current-time-in-seconds)
1.0
(vector 1.0 1.0 1.0)))
particles))))
asteroids))
bullets)
(for-each
(lambda (a)
(is-asteroid a)
(when (<= (pt-distance a.pos ship.pos) a.radius)
(set! particles
(append (list-ec (: i 100)
(make-particle ship.pos
(pt*n (angle->pt
(radians
(random-integer 360)))
(random-integer 100))
(current-time-in-seconds)
1.0
(vector 0.0 1.0 1.0)))
particles))
(set! ship (make-spaceship (pt (/ width 2.0) (/ height 2.0))
(pt 0.0 0.0)
0.0
0.0))
))
asteroids)
(when (null? asteroids)
(set! level (+ level 1))
(display "level: ")
(display level)
(newline)
(set! asteroids
(list-ec (: i (+ number-of-starting-asteroids level))
(make-asteroid (pt (inexact (random-integer width))
(inexact (random-integer height)))
(pt (inexact (+ -50 (random-integer 100)))
(inexact (+ -50 (random-integer 100))))
50.0))))
;; ship pack contact
(when (<= (pt-distance ship.pos pack.pos) 10.0)
(set! ammo (+ ammo 5))
(set! pack (make-bullet-pack (pt (inexact (random-integer width))
(inexact (random-integer height)))
(pt (inexact (+ -50 (random-integer 100)))
(inexact (+ -50 (random-integer 100))))))
(say "ammo: " ammo))
)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(glutIdleFunc
(lambda ()
(update-system)
(glutPostRedisplay)))
(glutKeyboardFunc
(lambda (key x y)
(case (integer->char key)
((#\w)
(ship.vel! (pt+ ship.vel (pt*n (angle->pt ship.theta) 50.0)))
(set! particles
(append (list-ec (: i 10)
(make-particle ship.pos
(pt*n
(angle->pt
(+ ship.theta
(radians 180.0)
(radians (+ -45 (random-integer 90)))
))
(random-integer 50)
)
(current-time-in-seconds)
1.0
(vector 1.0 1.0 0.0)))
particles))
)
((#\a) (ship.theta! (+ ship.theta (radians 20.0))))
((#\d) (ship.theta! (- ship.theta (radians 20.0))))
((#\s) (ship.vel! (pt 0.0 0.0)))
((#\x) (ship.theta! (+ ship.theta (radians 180.0))))
((#\space)
(when (> ammo 0)
(set! ammo (- ammo 1))
(set! bullets
(cons
(make-bullet ship.pos
(pt+ ship.vel
(pt*n (angle->pt ship.theta) 400.0))
(current-time-in-seconds))
bullets)))
(say "ammo: " ammo)
)
)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(say "w - Thrusters")
(say "a/d - Left/Right")
(say "s - Stop")
(say "x - Flip")
(say "spc - Laser")
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(glutMainLoop)

39
test/fixtures/cuda.cu vendored Normal file
View File

@@ -0,0 +1,39 @@
void foo()
{
cudaArray* cu_array;
texture<float, 2, cudaReadModeElementType> tex;
// Allocate array
cudaChannelFormatDesc description = cudaCreateChannelDesc<float>();
cudaMallocArray(&cu_array, &description, width, height);
// Copy image data to array
cudaMemcpyToArray(cu_array, image, width*height*sizeof(float), cudaMemcpyHostToDevice);
// Set texture parameters (default)
tex.addressMode[0] = cudaAddressModeClamp;
tex.addressMode[1] = cudaAddressModeClamp;
tex.filterMode = cudaFilterModePoint;
tex.normalized = false; // do not normalize coordinates
// Bind the array to the texture
cudaBindTextureToArray(tex, cu_array);
// Run kernel
dim3 blockDim(16, 16, 1);
dim3 gridDim((width + blockDim.x - 1)/ blockDim.x, (height + blockDim.y - 1) / blockDim.y, 1);
kernel<<< gridDim, blockDim, 0 >>>(d_data, height, width);
// Unbind the array from the texture
cudaUnbindTexture(tex);
} //end foo()
__global__ void kernel(float* odata, int height, int width)
{
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
if (x < width && y < height) {
float c = tex2D(tex, x, y);
odata[y*width+x] = c;
}
}

BIN
test/fixtures/dog.o vendored Executable file

Binary file not shown.

1
test/fixtures/file.json vendored Normal file
View File

@@ -0,0 +1 @@
{"foo": "bar"}

BIN
test/fixtures/foo bar.jar vendored Normal file

Binary file not shown.

BIN
test/fixtures/foo.bin vendored Normal file

Binary file not shown.

3
test/fixtures/foo.nim vendored Normal file
View File

@@ -0,0 +1,3 @@
# Hello world program
echo "Hello world!"

BIN
test/fixtures/foo.pdf vendored Normal file

Binary file not shown.

BIN
test/fixtures/foo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
test/fixtures/git.deb vendored Normal file

Binary file not shown.

BIN
test/fixtures/git.exe vendored Executable file

Binary file not shown.

1
test/fixtures/hello.ahk vendored Normal file
View File

@@ -0,0 +1 @@
MsgBox, Hello`, World!

BIN
test/fixtures/linguist.gem vendored Normal file

Binary file not shown.

BIN
test/fixtures/octocat.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
test/fixtures/octocat.psd vendored Normal file

Binary file not shown.

BIN
test/fixtures/pkg/linguist.gem vendored Normal file

Binary file not shown.

View File

@@ -94,13 +94,13 @@ class TestBlob < Test::Unit::TestCase
def test_text
assert blob("README").text?
assert blob("dump.sql").text?
assert blob("file.json").text?
assert blob("file.txt").text?
assert blob("md").text?
assert blob("script.sh").text?
assert blob("tender.md").text?
assert blob("txt").text?
assert blob("zip").text?
end
def test_image