Permalink
Browse files

adding lists, graph, functors, interpolators, unit tests, and import.ck

  • Loading branch information...
1 parent 9745bb5 commit 3b16cd29a900f17f038d64c6129563f6cdfcb4dc @heuermh committed Jan 29, 2009
Showing with 6,009 additions and 0 deletions.
  1. +29 −0 Acos.ck
  2. +121 −0 ArrayList.ck
  3. +244 −0 ArrayListTest.ck
  4. +29 −0 Asin.ck
  5. +227 −0 Assert.ck
  6. +29 −0 Atan.ck
  7. +31 −0 BinaryFunction.ck
  8. +31 −0 BinaryPredicate.ck
  9. +29 −0 BinaryProcedure.ck
  10. +674 −0 COPYING
  11. +29 −0 Ceil.ck
  12. +29 −0 CircularIn.ck
  13. +26 −0 CircularInOut.ck
  14. +29 −0 CircularOut.ck
  15. +31 −0 Comparator.ck
  16. +33 −0 CompositeFloatFunction.ck
  17. +33 −0 CompositeFunction.ck
  18. +33 −0 CompositeIntFunction.ck
  19. +29 −0 Cos.ck
  20. +29 −0 Cosh.ck
  21. +29 −0 CubicIn.ck
  22. +36 −0 CubicInOut.ck
  23. +29 −0 CubicOut.ck
  24. +28 −0 Edge.ck
  25. +29 −0 Exp.ck
  26. +29 −0 ExponentialIn.ck
  27. +26 −0 ExponentialInOut.ck
  28. +29 −0 ExponentialOut.ck
  29. +107 −0 FloatArrayList.ck
  30. +225 −0 FloatArrayListTest.ck
  31. +31 −0 FloatComparator.ck
  32. +31 −0 FloatFloatFloatFloatFunction.ck
  33. +29 −0 FloatFloatFloatFloatPredicate.ck
  34. +31 −0 FloatFloatFloatFunction.ck
  35. +29 −0 FloatFloatFloatPredicate.ck
  36. +31 −0 FloatFloatFunction.ck
  37. +31 −0 FloatFloatPredicate.ck
  38. +29 −0 FloatFloatProcedure.ck
  39. +31 −0 FloatFunction.ck
  40. +158 −0 FloatFunctions.ck
  41. +34 −0 FloatIterator.ck
  42. +109 −0 FloatList.ck
  43. +39 −0 FloatListIterator.ck
  44. +31 −0 FloatPredicate.ck
  45. +29 −0 FloatProcedure.ck
  46. +29 −0 Floor.ck
  47. +31 −0 Function.ck
  48. +32 −0 Functions.ck
  49. +128 −0 Graph.ck
  50. +40 −0 GraphTest.ck
  51. +46 −0 Graphs.ck
  52. +86 −0 GraphsTest.ck
  53. +21 −0 HEADER.txt
  54. +29 −0 Identity.ck
  55. +107 −0 IntArrayList.ck
  56. +227 −0 IntArrayListTest.ck
  57. +31 −0 IntComparator.ck
  58. +31 −0 IntFunction.ck
  59. +32 −0 IntFunctions.ck
  60. +31 −0 IntIntFunction.ck
  61. +31 −0 IntIntIntFunction.ck
  62. +31 −0 IntIntIntIntFunction.ck
  63. +31 −0 IntIntIntIntPredicate.ck
  64. +29 −0 IntIntIntIntProcedure.ck
  65. +31 −0 IntIntIntPredicate.ck
  66. +29 −0 IntIntIntProcedure.ck
  67. +31 −0 IntIntPredicate.ck
  68. +29 −0 IntIntProcedure.ck
  69. +34 −0 IntIterator.ck
  70. +109 −0 IntList.ck
  71. +39 −0 IntListIterator.ck
  72. +31 −0 IntPredicate.ck
  73. +29 −0 IntProcedure.ck
  74. +27 −0 Interpolation.ck
  75. +29 −0 Inverse.ck
  76. +34 −0 Iterator.ck
  77. +29 −0 LinearIn.ck
  78. +26 −0 LinearInOut.ck
  79. +29 −0 LinearOut.ck
  80. +109 −0 List.ck
  81. +39 −0 ListIterator.ck
  82. +29 −0 Log.ck
  83. +29 −0 Log10.ck
  84. +29 −0 Log2.ck
  85. +29 −0 Negate.ck
  86. +33 −0 Node.ck
  87. +31 −0 Predicate.ck
  88. +29 −0 Procedure.ck
  89. +29 −0 QuadraticIn.ck
  90. +36 −0 QuadraticInOut.ck
  91. +29 −0 QuadraticOut.ck
  92. +29 −0 QuarticIn.ck
  93. +36 −0 QuarticInOut.ck
  94. +29 −0 QuarticOut.ck
  95. +31 −0 QuaternaryFunction.ck
  96. +31 −0 QuaternaryPredicate.ck
  97. +29 −0 QuinticIn.ck
  98. +36 −0 QuinticInOut.ck
  99. +29 −0 QuinticOut.ck
  100. +29 −0 Random.ck
  101. +29 −0 RandomFloor.ck
  102. +29 −0 RandomThreshold.ck
  103. +29 −0 Round.ck
  104. +29 −0 Sin.ck
  105. +29 −0 Sinh.ck
  106. +26 −0 SinusoidalIn.ck
  107. +26 −0 SinusoidalInOut.ck
  108. +26 −0 SinusoidalOut.ck
  109. +29 −0 Sqrt.ck
  110. +29 −0 Tan.ck
  111. +29 −0 Tanh.ck
  112. +31 −0 TertiaryFunction.ck
  113. +31 −0 TertiaryPredicate.ck
  114. +29 −0 TertiaryProcedure.ck
  115. +29 −0 Trunc.ck
  116. +31 −0 UnaryFunction.ck
  117. +31 −0 UnaryPredicate.ck
  118. +29 −0 UnaryProcedure.ck
  119. +31 −0 Uniform.ck
  120. +155 −0 import.ck
  121. +28 −0 tests.ck
View
29 Acos.ck
@@ -0,0 +1,29 @@
+/*
+
+ LiCK Library for ChucK.
+ Copyright (c) 2007-2009 held jointly by the individual authors.
+
+ This file is part of LiCK.
+
+ LiCK is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LiCK 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LiCK. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+public class Acos extends FloatFunction
+{
+ fun float evaluate(float arg)
+ {
+ return Math.acos(arg);
+ }
+}
View
@@ -0,0 +1,121 @@
+/*
+
+ LiCK Library for ChucK.
+ Copyright (c) 2007-2009 held jointly by the individual authors.
+
+ This file is part of LiCK.
+
+ LiCK is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LiCK 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LiCK. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+public class ArrayList extends List
+{
+ Object values[0];
+
+ fun int size()
+ {
+ return values.size();
+ }
+
+ fun int size(int capacity)
+ {
+ return values.size(capacity);
+ }
+
+ fun Object get(int index)
+ {
+ return values[index];
+ }
+
+ fun Object sample()
+ {
+ Math.rand2(0, size() - 1) => int index;
+ return get(index);
+ }
+
+ fun void add(Object value)
+ {
+ values << value;
+ }
+
+ fun void addAll(List list)
+ {
+ list.iterator() @=> Iterator it;
+ while (it.hasNext())
+ {
+ add(it.next());
+ }
+ }
+
+ fun void set(int index, Object value)
+ {
+ value @=> values[index];
+ }
+
+ // todo: move to List etc.
+ fun int contains(Object value)
+ {
+ for (0 => int i; i < size(); i++)
+ {
+ if (value == get(i))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ fun Iterator iterator()
+ {
+ ListIterator i;
+ this @=> i.list;
+ return i;
+ }
+
+ fun void forEach(UnaryProcedure procedure)
+ {
+ for (0 => int i; i < size(); i++)
+ {
+ procedure.run(values[i]);
+ }
+ }
+
+ fun void forEach(UnaryPredicate predicate, UnaryProcedure procedure)
+ {
+ for (0 => int i; i < size(); i++)
+ {
+ if (predicate.test(values[i]))
+ {
+ procedure.run(values[i]);
+ }
+ }
+ }
+
+ fun void assign(Object value)
+ {
+ for (0 => int i; i < size(); i++)
+ {
+ value @=> values[i];
+ }
+ }
+
+ fun void transform(UnaryFunction fn)
+ {
+ for (0 => int i; i < size(); i++)
+ {
+ fn.evaluate(values[i]) @=> values[i];
+ }
+ }
+}
View
@@ -0,0 +1,244 @@
+/*
+
+ LiCK Library for ChucK.
+ Copyright (c) 2007-2009 held jointly by the individual authors.
+
+ This file is part of LiCK.
+
+ LiCK is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ LiCK 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LiCK. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+class NeverTrue extends UnaryPredicate
+{
+ // empty
+}
+
+class AlwaysTrue extends UnaryPredicate
+{
+ fun int test(Object arg)
+ {
+ return true;
+ }
+}
+
+class Nullify extends UnaryFunction
+{
+ fun Object evaluate(Object arg)
+ {
+ return null;
+ }
+}
+
+class Foo
+{
+ fun int foo()
+ {
+ return 1;
+ }
+}
+
+// unit test for ArrayList
+
+class ArrayListTest extends Assert
+{
+ Object foo;
+ Object bar;
+ Object baz;
+ Object qux;
+ Object garply;
+
+ {
+ true => exitOnFailure;
+ testConstructor();
+ testSize();
+ testGetAddSet();
+ testIterator();
+ testForEach();
+ testAssign();
+ testTransform();
+ testAddAll();
+ testFoo();
+
+ <<<"ArrayListTest ok">>>;
+ }
+
+ fun void testConstructor()
+ {
+ ArrayList list;
+ assertNotNull(list);
+ }
+
+ fun void testSize()
+ {
+ ArrayList list;
+ assertNotNull(list);
+ assertEquals(0, list.size());
+ assertTrue(list.isEmpty());
+
+ assertEquals(16, list.size(16));
+ assertFalse(list.isEmpty());
+
+ assertEquals(0, list.size(0));
+ assertTrue(list.isEmpty());
+ }
+
+ fun void testGetAddSet()
+ {
+ ArrayList list;
+
+ list.add(foo);
+ assertEquals(1, list.size());
+ assertFalse(list.isEmpty());
+ assertEquals(foo, list.get(0));
+
+ list.set(0, bar);
+ assertEquals(bar, list.get(0));
+
+ // throws ArrayOutofBounds
+ //list.get(99);
+ //list.set(baz, 99);
+ }
+
+ fun void testIterator()
+ {
+ ArrayList list;
+ list.add(foo);
+ list.add(bar);
+ list.add(baz);
+
+ list.iterator() @=> Iterator iterator;
+ assertNotNull(iterator);
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertNotNull(value);
+ }
+ }
+
+ fun void testForEach()
+ {
+ ArrayList list;
+ list.add(foo);
+ list.add(bar);
+ list.add(baz);
+
+ UnaryProcedure procedure;
+ list.forEach(procedure);
+
+ NeverTrue neverTrue;
+ list.forEach(neverTrue, procedure);
+
+ AlwaysTrue alwaysTrue;
+ list.forEach(alwaysTrue, procedure);
+
+ // throws NullPointerException
+ //list.forEach(null);
+ //list.forEach(null, procedure);
+ //list.forEach(alwaysTrue, null);
+ }
+
+ fun void testAssign()
+ {
+ ArrayList list;
+ Iterator @ iterator;
+ list.size(16);
+
+ list.iterator() @=> iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertNull(value);
+ }
+
+ list.assign(foo);
+ list.iterator() @=> iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertEquals(foo, value);
+ }
+
+ list.assign(bar);
+ list.iterator() @=> iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertEquals(bar, value);
+ }
+ }
+
+ fun void testTransform()
+ {
+ ArrayList list;
+ Iterator @ iterator;
+ Nullify nullify;
+ list.size(16);
+
+ list.assign(foo);
+ list.iterator() @=> iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertEquals(foo, value);
+ }
+
+ list.transform(nullify);
+ list.iterator() @=> iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertNull(value);
+ }
+
+ // throws NullPointerException
+ //list.transform(null);
+ }
+
+ fun void testAddAll()
+ {
+ ArrayList list0;
+ list0.size(16);
+ list0.assign(foo);
+
+ ArrayList list1;
+ list1.size(16);
+ list1.assign(bar);
+
+ ArrayList list2;
+ list2.addAll(list0);
+ list2.addAll(list1);
+ assertEquals(32, list2.size());
+
+ list2.iterator() @=> Iterator iterator;
+ while (iterator.hasNext())
+ {
+ iterator.next() @=> Object value;
+ assertTrue((value == foo) || (value == bar));
+ }
+ }
+
+ fun void testFoo()
+ {
+ ArrayList list0;
+ Foo fooIn;
+ list0.add(fooIn);
+ list0.get(0) $ Foo @=> Foo fooOut;
+ assertEquals(fooIn, fooOut);
+ <<<fooOut.foo()>>>;
+ }
+}
+
+ArrayListTest arrayListTest;
+1::second => now;
Oops, something went wrong.

0 comments on commit 3b16cd2

Please sign in to comment.