joules 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +2 -1
- data/lib/joules/circular_motion.rb +13 -13
- data/lib/joules/constants.rb +1 -1
- data/lib/joules/conversion.rb +1 -1
- data/lib/joules/density.rb +1 -1
- data/lib/joules/electric_fields.rb +1 -1
- data/lib/joules/electricity.rb +1 -1
- data/lib/joules/energy_work_power.rb +1 -1
- data/lib/joules/forces.rb +1 -1
- data/lib/joules/geometry.rb +1 -1
- data/lib/joules/gravitational_fields.rb +1 -1
- data/lib/joules/kinematics.rb +1 -1
- data/lib/joules/magnetic_fields.rb +1 -1
- data/lib/joules/mass_weight.rb +1 -1
- data/lib/joules/momentum_impulse.rb +1 -1
- data/lib/joules/oscillations.rb +1 -1
- data/lib/joules/pressure.rb +1 -1
- data/lib/joules/quantum.rb +1 -1
- data/lib/joules/stress_strain.rb +1 -1
- data/lib/joules/thermodynamics.rb +1 -1
- data/lib/joules/waves.rb +19 -1
- data/lib/joules.rb +1 -1
- data/test/test_joules.rb +32 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 099b17d28098801dae8781ee30b0bbcf4cee23a8
|
4
|
+
data.tar.gz: b2b53b493896f5bccfa160f663996c541ff1563e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01e73b536d71dcac4af085b7d04393af6e8052ef5920e19f19ce3f97c7857134b3fa7ae4298f671a0e256aa87a62b46195cb2fa48ad4d66aa098be5a00eba06
|
7
|
+
data.tar.gz: a214b4986b5f565e8c39568bc4c75ff9516d6cf22f59f1ce46bc0eec733bb65ba0eeae2e97448a4ba5f338cfe46f7aab97cb02ae6afb6bdc2382ac1ec767ee2c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](http://forthebadge.com)
|
4
4
|
|
5
5
|
[](http://badge.fury.io/rb/joules)
|
6
|
+
[](https://travis-ci.org/elailai94/Joules)
|
6
7
|
[](https://inch-ci.org/github/elailai94/Joules)
|
7
8
|
|
8
9
|
### About
|
@@ -16,7 +17,7 @@ gem build joules.gemspec
|
|
16
17
|
|
17
18
|
### Library Installation
|
18
19
|
```Bash
|
19
|
-
gem install joules-0.4.
|
20
|
+
gem install joules-0.4.3.gem
|
20
21
|
```
|
21
22
|
|
22
23
|
### Library Import
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing circular motion formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Circular motion module (circular_motion.rb)
|
@@ -25,9 +25,9 @@ module Joules
|
|
25
25
|
# Joules.angular_velocity_v1(9, 3) #=> 3.0
|
26
26
|
# @note There is one other method for calculating angular velocity.
|
27
27
|
def angular_velocity_v1(linear_velocity, radius)
|
28
|
-
|
28
|
+
if radius.zero?
|
29
29
|
raise ZeroDivisionError.new('divided by 0')
|
30
|
-
|
30
|
+
else
|
31
31
|
return linear_velocity / radius.to_f
|
32
32
|
end
|
33
33
|
end
|
@@ -41,7 +41,7 @@ module Joules
|
|
41
41
|
# Joules.angular_velocity_v2(1.5) #=> 9.42477796076938
|
42
42
|
# @note There is one other method for calculating angular velocity.
|
43
43
|
def angular_velocity_v2(frequency_of_rotation)
|
44
|
-
|
44
|
+
return 2 * Math::PI * frequency_of_rotation
|
45
45
|
end
|
46
46
|
|
47
47
|
# Calculates the angular acceleration given initial angular velocity, final angular velocity, and time.
|
@@ -57,9 +57,9 @@ module Joules
|
|
57
57
|
# @example
|
58
58
|
# Joules.angular_acceleration(20, 35, 2.4) #=> 6.25
|
59
59
|
def angular_acceleration(initial_angular_velocity, final_angular_velocity, time)
|
60
|
-
|
60
|
+
if time.zero?
|
61
61
|
raise ZeroDivisionError.new('divided by 0')
|
62
|
-
|
62
|
+
else
|
63
63
|
return (final_angular_velocity - initial_angular_velocity) / time.to_f
|
64
64
|
end
|
65
65
|
end
|
@@ -76,10 +76,10 @@ module Joules
|
|
76
76
|
# Joules.centripetal_acceleration_v1(9, 3) #=> 27.0
|
77
77
|
# @note There is one other method for calculating centripetal acceleration.
|
78
78
|
def centripetal_acceleration_v1(linear_velocity, radius)
|
79
|
-
|
79
|
+
if radius.zero?
|
80
80
|
raise ZeroDivisionError.new('divided by 0')
|
81
|
-
|
82
|
-
|
81
|
+
else
|
82
|
+
return (linear_velocity ** 2.0) / radius
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -94,7 +94,7 @@ module Joules
|
|
94
94
|
# Joules.centripetal_acceleration_v2(3, 3) #=> 27.0
|
95
95
|
# @note There is one other method for calculating centripetal acceleration.
|
96
96
|
def centripetal_acceleration_v2(angular_velocity, radius)
|
97
|
-
|
97
|
+
return (angular_velocity ** 2.0) * radius
|
98
98
|
end
|
99
99
|
|
100
100
|
# Calculates the centripetal force given mass, linear velocity, and radius.
|
@@ -110,9 +110,9 @@ module Joules
|
|
110
110
|
# Joules.centripetal_force_v1(2000, 5.56, 2.1) #=> 29441.523809523802
|
111
111
|
# @note There is one other method for calculating centripetal force.
|
112
112
|
def centripetal_force_v1(mass, linear_velocity, radius)
|
113
|
-
|
113
|
+
if radius.zero?
|
114
114
|
raise ZeroDivisionError.new('divided by 0')
|
115
|
-
|
115
|
+
else
|
116
116
|
return (mass * (linear_velocity ** 2.0)) / radius
|
117
117
|
end
|
118
118
|
end
|
@@ -130,7 +130,7 @@ module Joules
|
|
130
130
|
# Joules.centripetal_force_v2(53.5, 3, 3) #=> 1444.5
|
131
131
|
# @note There is one other method for calculating centripetal force.
|
132
132
|
def centripetal_force_v2(mass, angular_velocity, radius)
|
133
|
-
|
133
|
+
return mass * (angular_velocity ** 2.0) * radius
|
134
134
|
end
|
135
135
|
|
136
136
|
# Calculates the angular momentum given moment of inertia and angular velocity.
|
data/lib/joules/constants.rb
CHANGED
data/lib/joules/conversion.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing conversion formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Conversion module (conversion.rb)
|
data/lib/joules/density.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing electric fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Electric fields module (electric_fields.rb)
|
data/lib/joules/electricity.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing electricity formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Electricity module (electricity.rb)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing energy, work, and power formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Energy, work, and power module (energy_work_power.rb)
|
data/lib/joules/forces.rb
CHANGED
data/lib/joules/geometry.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing gravitational fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Gravitational fields module (gravitational_fields.rb)
|
data/lib/joules/kinematics.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing kinematics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing magnetic fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Magnetic fields module (magnetic_fields.rb)
|
data/lib/joules/mass_weight.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing mass and weight formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing momentum and impulse formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
data/lib/joules/oscillations.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing oscillations formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Oscillations module (oscillations.rb)
|
data/lib/joules/pressure.rb
CHANGED
data/lib/joules/quantum.rb
CHANGED
data/lib/joules/stress_strain.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing stress and strain formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Stress and strain module (stress_strain.rb)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing thermodynamics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Thermodynamics module (thermodynamics.rb)
|
data/lib/joules/waves.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing waves formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Waves module (waves.rb)
|
@@ -97,6 +97,24 @@ module Joules
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# Calculates the intensity of a wave given power and area.
|
101
|
+
# @param power [Int, Float]
|
102
|
+
# power is in watts
|
103
|
+
# @param area [Int, Float]
|
104
|
+
# area > 0; area is in metres squared
|
105
|
+
# @return [Float]
|
106
|
+
# return value is in watts per metre squared
|
107
|
+
# @raise [ZeroDivisionError] if area = 0
|
108
|
+
# @example
|
109
|
+
# Joules.intensity(50, 2) #=> 25.0
|
110
|
+
def intensity(power, area)
|
111
|
+
if area.zero?
|
112
|
+
raise ZeroDivisionError.new('divided by 0')
|
113
|
+
else
|
114
|
+
return power / area.to_f
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
100
118
|
# Calculates the refractive index of a substance given angle of incidence and angle of refraction.
|
101
119
|
# @param angle_of_incidence [Int, Float]
|
102
120
|
# angle_of_incidence is in degrees
|
data/lib/joules.rb
CHANGED
data/test/test_joules.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for testing the Joules module
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.4.
|
6
|
+
# @version: 0.4.3 13/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Testing module for joules.rb (test_joules.rb)
|
@@ -14,6 +14,31 @@ include Joules
|
|
14
14
|
|
15
15
|
EPSILON = 0.00001
|
16
16
|
|
17
|
+
# Unit tests for circular motion module
|
18
|
+
class CircularMotionTests < Test::Unit::TestCase
|
19
|
+
def test_angular_velocity_v1_extreme_1
|
20
|
+
assert_in_epsilon(0, angular_velocity_v1(0,0.001), EPSILON)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_angular_velocity_v1_extreme_2
|
24
|
+
assert_in_epsilon(1.03010, angular_velocity_v1(928476103, 901348726), EPSILON)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_angular_velocity_v1_big_divisor
|
28
|
+
assert_in_epsilon(6.32386e-09, angular_velocity_v1(5.7, 901348726), EPSILON)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_angular_velocity_v1_zero_division
|
32
|
+
assert_raise(ZeroDivisionError) do
|
33
|
+
angular_velocity_v1(1, 0)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_angular_velocity_v1_example
|
38
|
+
assert_in_epsilon(3, angular_velocity_v1(9, 3), EPSILON)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
17
42
|
# Unit tests for kinematics module
|
18
43
|
class KinematicsTests < Test::Unit::TestCase
|
19
44
|
def test_avg_speed_extreme_1
|
@@ -27,4 +52,10 @@ class KinematicsTests < Test::Unit::TestCase
|
|
27
52
|
def test_avg_speed_big_divisor
|
28
53
|
assert_in_epsilon(6.32386e-09, avg_speed(5.7, 901348726), EPSILON)
|
29
54
|
end
|
55
|
+
|
56
|
+
def test_avg_speed_zero_division
|
57
|
+
assert_raise(ZeroDivisionError) do
|
58
|
+
avg_speed(1, 0)
|
59
|
+
end
|
60
|
+
end
|
30
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elisha Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Joules is a library (gem) for providing simple Physics formulas\n
|
14
14
|
\ in kinematics, forces, waves, electricity, and so much more. A\n selection
|