molecules 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,147 @@
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
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,3 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ Dir.glob("./**/*_test.rb").each {|test| require test}
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'tap'
3
+ require 'tap/test'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: molecules
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Chiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-11 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: constants
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.0
24
+ version:
25
+ description:
26
+ email: simon.a.chiang@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - MIT-LICENSE
34
+ files:
35
+ - MIT-LICENSE
36
+ - Rakefile
37
+ - README
38
+ - lib/molecules.rb
39
+ - lib/molecules/calc.rb
40
+ - lib/molecules/empirical_formula.rb
41
+ - lib/molecules/libraries/polypeptide.rb
42
+ - lib/molecules/libraries/residue.rb
43
+ - lib/molecules/utils.rb
44
+ - tap.yml
45
+ - test/molecules/calc_test.rb
46
+ - test/molecules/empirical_formula_class_test.rb
47
+ - test/molecules/empirical_formula_test.rb
48
+ - test/molecules/libraries/polypeptide_test.rb
49
+ - test/molecules/libraries/residue_test.rb
50
+ - test/molecules/utils_test.rb
51
+ - test/molecules_test.rb
52
+ - test/molecules_test_helper.rb
53
+ - test/molecules_test_suite.rb
54
+ - test/tap_test_helper.rb
55
+ has_rdoc: true
56
+ homepage: http://bioactive.rubyforge.org/molecules/
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: bioactive
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: A library of molecules for scientific calculations in Ruby.
81
+ test_files:
82
+ - test/molecules_test_suite.rb