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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebea8b8abdde03c40493dc8bccd291448aae450a
4
- data.tar.gz: 372309d709a479b124a2f45ca48fe2082cc93898
3
+ metadata.gz: 099b17d28098801dae8781ee30b0bbcf4cee23a8
4
+ data.tar.gz: b2b53b493896f5bccfa160f663996c541ff1563e
5
5
  SHA512:
6
- metadata.gz: d9b14eca944849f3a96e0d739bd2afa12d3a59d6a587a035b6696fe792c26cc3634c522c878207060afba456f1a8b5c9217a9796085a0cb70b6e434299cf3d70
7
- data.tar.gz: 7958efaaca9e74f5d623d305cb62eaf3d37755647455fc4c3e2df6088673c89c15d354e233084c2b04313ac47e60fb20054fa20582bdc9fee3c3d7aa4e91cfd4
6
+ metadata.gz: d01e73b536d71dcac4af085b7d04393af6e8052ef5920e19f19ce3f97c7857134b3fa7ae4298f671a0e256aa87a62b46195cb2fa48ad4d66aa098be5a00eba06
7
+ data.tar.gz: a214b4986b5f565e8c39568bc4c75ff9516d6cf22f59f1ce46bc0eec733bb65ba0eeae2e97448a4ba5f338cfe46f7aab97cb02ae6afb6bdc2382ac1ec767ee2c
data/CHANGELOG.md CHANGED
@@ -36,3 +36,6 @@
36
36
  #### Version 0.4.2
37
37
  * Added more Physics formulas in electricity and force
38
38
  * Added more geometric formulas commonly used in Physics
39
+
40
+ #### Version 0.4.3
41
+ * Added more Physics formulas in waves
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Ruby Badge](http://forthebadge.com/images/badges/built-with-ruby.svg)](http://forthebadge.com)
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/joules.svg)](http://badge.fury.io/rb/joules)
6
+ [![Build Status](https://travis-ci.org/elailai94/Joules.svg?)](https://travis-ci.org/elailai94/Joules)
6
7
  [![Inline Docs](http://inch-ci.org/github/elailai94/joules.svg?style=shields)](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.2.gem
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.2 10/06/2015
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
- if radius.zero?
28
+ if radius.zero?
29
29
  raise ZeroDivisionError.new('divided by 0')
30
- else
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
- return 2 * Math::PI * frequency_of_rotation
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
- if time.zero?
60
+ if time.zero?
61
61
  raise ZeroDivisionError.new('divided by 0')
62
- else
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
- if radius.zero?
79
+ if radius.zero?
80
80
  raise ZeroDivisionError.new('divided by 0')
81
- else
82
- return (linear_velocity ** 2.0) / radius
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
- return (angular_velocity ** 2.0) * radius
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
- if radius.zero?
113
+ if radius.zero?
114
114
  raise ZeroDivisionError.new('divided by 0')
115
- else
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
- return mass * (angular_velocity ** 2.0) * radius
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.
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing constants
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Constants module (constants.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing conversion formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Conversion module (conversion.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing density formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Density module (density.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing electric fields formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Electric fields module (electric_fields.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing electricity formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
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.2 10/06/2015
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
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing forces formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Forces module (forces.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing geometry formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Geometry module (geometry.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing gravitational fields formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Gravitational fields module (gravitational_fields.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing kinematics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
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.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Magnetic fields module (magnetic_fields.rb)
@@ -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.2 10/06/2015
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.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Momentum and impulse module (momentum_impulse.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing oscillations formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Oscillations module (oscillations.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing pressure formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Pressure module (pressure.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing quantum formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Quantum module (quantum.rb)
@@ -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.2 10/06/2015
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.2 10/06/2015
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.2 10/06/2015
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
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing Physics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.4.2 10/06/2015
6
+ # @version: 0.4.3 13/06/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Joules module (joules.rb)
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.2 10/06/2015
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.2
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-10 00:00:00.000000000 Z
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