molecules 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,147 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '../molecules_test_helper.rb')
2
- require 'molecules/utils'
3
-
4
- class UtilsTest < Test::Unit::TestCase
5
- include Molecules::Utils
6
-
7
- #
8
- # round test
9
- #
10
-
11
- def test_round
12
- assert_equal 0, round(0.20, 0)
13
- assert_equal 0.2, round(0.20, 1)
14
- assert_equal 0.2, round(0.20, 2)
15
- assert_equal 0.2, round(0.20, 3)
16
-
17
- assert_equal 0.2, round(0.18, 1)
18
- assert_equal 0.2, round(0.15, 1)
19
- assert_equal 0.1, round(0.13, 1)
20
- assert_equal 0.13, round(0.13, 3)
21
-
22
- assert_equal 10, round(13, -1)
23
- assert_equal 0, round(13, -2)
24
- end
25
-
26
- #
27
- # add
28
- #
29
-
30
- def test_add_adds_the_elements_of_b_to_a_at_corresponding_indicies
31
- assert_equal [2,3,4], add([1,3,-1], [1,0,5])
32
- end
33
-
34
- def test_add_multiplies_the_elements_of_b_by_factor
35
- assert_equal [3,3,9], add([1,3,-1], [1,0,5], 2)
36
- assert_equal [1,3,-1], add([1,3,-1], [1,0,5], 0)
37
- end
38
-
39
- def test_add_removes_trailing_zeros_from_a
40
- assert_equal [], add([1,1,1], [-1,-1,-1])
41
- end
42
-
43
- def test_add_returns_a
44
- a = [1,2,4]
45
- assert_equal a.object_id, add(a, [1,0,4]).object_id
46
- end
47
-
48
- def test_add_does_not_require_a_and_b_to_be_the_same_length
49
- a = [1,2]
50
- b = [1]
51
-
52
- assert_equal [2,2], add(a, b)
53
-
54
- a = [1,2]
55
- b = [1]
56
-
57
- assert_equal [2,2], add(b, a)
58
- end
59
-
60
- #
61
- # multiply test
62
- #
63
-
64
- def test_multiply_multiplies_elements_of_a_by_factor
65
- assert_equal [2,4,-6], multiply([1,2,-3], 2)
66
- assert_equal [-2,-4,6], multiply([1,2,-3], -2)
67
- end
68
-
69
- def test_multiply_clears_a_for_zero_factor
70
- assert_equal [], multiply([1,2,-3], 0)
71
- end
72
-
73
- def test_mulitply_returns_a
74
- a = [1,2,4]
75
- assert_equal a.object_id, multiply(a, 2).object_id
76
- assert_equal a.object_id, multiply(a, 0).object_id
77
- end
78
-
79
- #
80
- # count test
81
- #
82
-
83
- def test_count_documenation
84
- assert_equal [3, 2, 2] , count("abcabca", ["a", "b", "c"])
85
- assert_equal [3, 4], count("abcabca", ["a", "bc"])
86
- end
87
-
88
- #
89
- # benchmark tests
90
- #
91
-
92
- def test_round_speed
93
- benchmark_test(24) do |x|
94
- n = 100
95
- x.report("#{n}k 1234.5678.round") do
96
- (n*10**3).times { 1234.5678.round }
97
- end
98
-
99
- x.report("#{n}k 1234.5678 (2)") do
100
- (n*10**3).times { round(1234.5678, 2) }
101
- end
102
-
103
- x.report("#{n}k 1234.5678 (5)") do
104
- (n*10**3).times { round(1234.5678, 5) }
105
- end
106
- end
107
- end
108
-
109
- def test_add_speed
110
- benchmark_test(30) do |x|
111
- n = 100
112
- x.report("#{n}k add([1,3,-1], [1,0,5])") do
113
- (n*10**3).times { add([1,3,-1], [1,0,5]) }
114
- end
115
-
116
- x.report("#{n}k add([1,3,-1], [1])") do
117
- (n*10**3).times { add([1,3,-1], [1]) }
118
- end
119
-
120
- x.report("#{n}k add([1], [1,3,-1])") do
121
- (n*10**3).times { add([1], [1,3,-1]) }
122
- end
123
-
124
- x.report("#{n}k add([1,1,1], [-1,-1,-1])") do
125
- (n*10**3).times { add([1,1,1], [-1,-1,-1]) }
126
- end
127
-
128
- x.report("#{n}k add([1,3,-1], [1,0,5], 2)") do
129
- (n*10**3).times { add([1,3,-1], [1,0,5], 2) }
130
- end
131
- end
132
- end
133
-
134
- def test_multiply_speed
135
- benchmark_test(30) do |x|
136
- n = 100
137
- x.report("#{n}k multiply([1,3,-1], 2)") do
138
- (n*10**3).times { multiply([1,3,-1], 2) }
139
- end
140
-
141
- x.report("#{n}k multiply([1,3,-1], 0)") do
142
- (n*10**3).times { multiply([1,3,-1], 0) }
143
- end
144
- end
145
- end
146
-
147
- end
@@ -1,24 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'molecules_test_helper.rb')
2
- require 'molecules'
3
-
4
- class MoleculesTest < Test::Unit::TestCase
5
-
6
- include Molecules::Libraries
7
-
8
- def test_readme_documentation
9
- r = Residue::A
10
- assert_equal "Alanine", r.name
11
- assert_equal "Ala", r.abbr
12
- assert_equal "A", r.letter
13
- assert_equal "CH(3)", r.side_chain.to_s
14
- assert_in_delta 71.03711, r.mass, 0.00001
15
- assert_in_delta 44.05002, r.immonium_ion_mass, 0.00001
16
-
17
- p = Polypeptide.new("RPPGFSPFR")
18
- assert_equal "C(50)H(71)N(15)O(10)", p.to_s
19
- assert_in_delta 1041.5508, p.mass , 0.0001
20
-
21
- caffeine = Molecules::EmpiricalFormula.parse("C8H10N4O2")
22
- coffee = Molecules::EmpiricalFormula.parse("C8H10N4O2 + H2O")
23
- end
24
- end
@@ -1,31 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'benchmark'
4
- require 'pp'
5
-
6
- class Test::Unit::TestCase
7
- include Benchmark
8
-
9
- #
10
- # mass tests
11
- #
12
-
13
- def delta_mass
14
- 10**-5
15
- end
16
-
17
- def delta_abundance
18
- 10**-1
19
- end
20
-
21
- def benchmark_test(length=10, &block)
22
- if ENV["benchmark"] =~ /true/i
23
- puts
24
- puts method_name
25
- bm(length, &block)
26
- else
27
- print 'b'
28
- end
29
- end
30
-
31
- end
@@ -1,3 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
-
3
- Dir.glob("./**/*_test.rb").each {|test| require test}
@@ -1,3 +0,0 @@
1
- require 'rubygems'
2
- require 'tap'
3
- require 'tap/test'