etw_math 1.0.0 → 1.0.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/example.rb +1 -1
  3. data/lib/etw_math.rb +10 -10
  4. data/test.rb +239 -0
  5. metadata +5 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3413847b2d51689c22b3b14f40fe7694dba51b74707027fe2db2ac7db6180f4f
4
- data.tar.gz: 41fcd3d5409d95f27fea39df5cf1428fae23926b5044760e9ee198933a20225f
3
+ metadata.gz: d86434b8a584f7010ab5af15c06808ac7303d954bdb7497f388ca904ab3c7ff2
4
+ data.tar.gz: a9426882c4e1d820517cdc6fd68ad6ff235bc882e167d398b7c2164586bfa277
5
5
  SHA512:
6
- metadata.gz: ef322f376904ed61799bbdc433d62edeef6f904e140f6fcceca5efc699e3311a2aedc9e61540eee6c8bc273630f0b0dbcb1ec0ea657a1328f31ba79f147e0c70
7
- data.tar.gz: 7153d47d94bea65c19ea60c046db0290cf4d8cad4b81ffe50ed3686bf80f859c7db91ef60d79c734421fc1bb3c086f1d38e5b2b07df51cf7ce61de4e9f0a14e3
6
+ metadata.gz: 2f60687998b6b2a479c282f78fa4eb5b5b4884ffbd008342b89f9b71382dce10ed5008fc4a154a92983695544fbbd8e6bb1e4f2f30e75e4938a45b575c11cf8a
7
+ data.tar.gz: 28b38734754ef876e4c4727cbe4a3eeb8dce3fe1b1d4867c79bdbd3581d9d336600b949249773335d4afd38b46d77aea68cd8ed9a9521627ff029aacfd27ea2a
data/example.rb CHANGED
@@ -23,7 +23,7 @@
23
23
  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
24
  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
25
 
26
- require_relative 'etw_math'
26
+ require_relative 'lib/etw_math'
27
27
 
28
28
  puts "Input tests..."
29
29
  puts EtwMath.input_valid?(5)
data/lib/etw_math.rb CHANGED
@@ -28,7 +28,7 @@
28
28
  # This class contains various methods that perform Eat the World calculations
29
29
  class EtwMath
30
30
  # EtwMath version
31
- VERSION = "1.0.0"
31
+ VERSION = "1.0.1"
32
32
 
33
33
  # Number of seconds in 1 day
34
34
  SECONDS_PER_DAY = 86400
@@ -315,7 +315,7 @@ class EtwMath
315
315
  # @example
316
316
  # EtwMath.size_range_cost(5, 10) # 28,000
317
317
  def self.size_range_cost(starting_level, ending_level)
318
- return false if !input_valid?(starting_level, ending_level)
318
+ return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level
319
319
  format_number(5 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 5 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2))
320
320
  end
321
321
 
@@ -326,7 +326,7 @@ class EtwMath
326
326
  # @example
327
327
  # EtwMath.walk_range_cost(5, 10) # 378,000
328
328
  def self.walk_range_cost(starting_level, ending_level)
329
- return false if !input_valid?(starting_level, ending_level)
329
+ return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level
330
330
  format_number(67.5 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 67.5 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2))
331
331
  end
332
332
 
@@ -337,7 +337,7 @@ class EtwMath
337
337
  # @example
338
338
  # EtwMath.multi_range_cost(5, 10) # 14,000,000
339
339
  def self.multi_range_cost(starting_level, ending_level)
340
- return false if !input_valid?(starting_level, ending_level)
340
+ return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level
341
341
  format_number(2500 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 2500 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2))
342
342
  end
343
343
 
@@ -348,7 +348,7 @@ class EtwMath
348
348
  # @example
349
349
  # EtwMath.eat_range_cost(5, 10) # 28,000,000
350
350
  def self.eat_range_cost(starting_level, ending_level)
351
- return false if !input_valid?(starting_level, ending_level)
351
+ return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level
352
352
  format_number(5000 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 5000 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2))
353
353
  end
354
354
 
@@ -404,7 +404,7 @@ class EtwMath
404
404
  # @example
405
405
  # EtwMath.small_bite_delta_multi(9440, 10954) # 53
406
406
  def self.small_bite_delta_multi(starting_size, ending_size)
407
- return false if !input_valid?(starting_size, ending_size)
407
+ return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size
408
408
  begin
409
409
  format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.02).round)
410
410
  rescue # division by zero
@@ -419,7 +419,7 @@ class EtwMath
419
419
  # @example
420
420
  # EtwMath.medium_bite_delta_multi(9440, 10954) # 35
421
421
  def self.medium_bite_delta_multi(starting_size, ending_size)
422
- return false if !input_valid?(starting_size, ending_size)
422
+ return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size
423
423
  begin
424
424
  format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.03).round)
425
425
  rescue # division by zero
@@ -434,7 +434,7 @@ class EtwMath
434
434
  # @example
435
435
  # EtwMath.big_bite_delta_multi(9440, 10954) # 27
436
436
  def self.big_bite_delta_multi(starting_size, ending_size)
437
- return false if !input_valid?(starting_size, ending_size)
437
+ return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size
438
438
  begin
439
439
  format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.04).round)
440
440
  rescue # division by zero
@@ -489,7 +489,7 @@ class EtwMath
489
489
  # @param multi [Integer] Multiplier
490
490
  # @return [String, Boolean] String representation of an integer or false if input is invalid or division by zero occurs
491
491
  # @example
492
- # EtwMath.time_to_max(565, 101) # 4.82 minutes
492
+ # EtwMath.time_to_max(565, 101) # 00d:00h:04m:49s
493
493
  def self.time_to_max(size_level, multi)
494
494
  return false if !input_valid?(size_level, multi)
495
495
  begin
@@ -504,7 +504,7 @@ class EtwMath
504
504
  # @param multi [Integer] Multiplier
505
505
  # @return [String, Boolean] String representation of an integer or false if input is invalid or division by zero occurs
506
506
  # @example
507
- # EtwMath.time_to_max_small(140, 31) # 2.75 minutes
507
+ # EtwMath.time_to_max_small(140, 31) # 00d:00h:02m:45s
508
508
  def self.time_to_max_small(size_level, multi)
509
509
  return false if !input_valid?(size_level, multi)
510
510
  begin
data/test.rb ADDED
@@ -0,0 +1,239 @@
1
+ # test.rb - EtwMath unit tests
2
+ # Copyright (C) 2025 Lazy Villain
3
+ # https://github.com/LazyAntihero/etw_math
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ require_relative 'lib/etw_math'
27
+ require 'minitest/autorun'
28
+
29
+ class EtwMathTests < Minitest::Test
30
+ def test_version
31
+ assert_match(/^(\d+.\d+.\d+)$/, EtwMath::VERSION)
32
+ end
33
+
34
+ def test_seconds_per_day
35
+ assert_equal(86400, EtwMath::SECONDS_PER_DAY)
36
+ end
37
+
38
+ def test_seconds_per_hour
39
+ assert_equal(3600, EtwMath::SECONDS_PER_HOUR)
40
+ end
41
+
42
+ def test_seconds_per_minute
43
+ assert_equal(60, EtwMath::SECONDS_PER_MINUTE)
44
+ end
45
+
46
+ def test_format_number
47
+ assert_equal("1,234,567", EtwMath.format_number(1234567.89))
48
+ assert_equal("1,234,567.89", EtwMath.format_number(1234567.89, true))
49
+ end
50
+
51
+ def test_format_time
52
+ assert_equal("14d:06h:56m:07s", EtwMath.format_time(1234567))
53
+ assert_equal("1,428d:21h:33m:09s", EtwMath.format_time(123456789))
54
+ end
55
+
56
+ #def test_print_decimal
57
+ # assert_nil(EtwMath.print_decimal(1234.56789))
58
+ #end
59
+
60
+ def test_input_valid
61
+ assert(!EtwMath.input_valid?(-1))
62
+ assert(!EtwMath.input_valid?(0))
63
+ assert(!EtwMath.input_valid?('s'))
64
+ assert(!EtwMath.input_valid?(5, 200, -999))
65
+ assert(EtwMath.input_valid?(5))
66
+ assert(EtwMath.input_valid?(5, 200, 1999, 1))
67
+ end
68
+
69
+ def test_brown_crate_max
70
+ assert_equal("7,000,000", EtwMath.brown_crate_max(7000000))
71
+ assert(!EtwMath.brown_crate_max(-1))
72
+ end
73
+
74
+ def test_yellow_crate_max
75
+ assert_equal("14,000,000", EtwMath.yellow_crate_max(7000000))
76
+ assert(!EtwMath.yellow_crate_max(-1))
77
+ end
78
+
79
+ def test_purple_crate_max
80
+ assert_equal("21,000,000", EtwMath.purple_crate_max(7000000))
81
+ assert(!EtwMath.purple_crate_max(-1))
82
+ end
83
+
84
+ def test_jackpot_amount
85
+ assert_equal("35,000,000", EtwMath.jackpot_amount(7000000))
86
+ assert(!EtwMath.jackpot_amount(-1))
87
+ end
88
+
89
+ def test_walk_speed_value
90
+ assert_equal("310", EtwMath.walk_speed_value(150))
91
+ assert(!EtwMath.walk_speed_value(-1))
92
+ end
93
+
94
+ def test_walk_speed_level
95
+ assert_equal("145", EtwMath.walk_speed_level(300))
96
+ assert(!EtwMath.walk_speed_level(-1))
97
+ end
98
+
99
+ def test_size_at_level
100
+ assert_equal("505,000", EtwMath.size_at_level(100))
101
+ assert(!EtwMath.size_at_level(-1))
102
+ end
103
+
104
+ def test_level_at_size
105
+ assert_equal("100", EtwMath.level_at_size(505000))
106
+ assert(!EtwMath.level_at_size(-1))
107
+ end
108
+
109
+ def test_optimal_size_level_threshold
110
+ assert_equal("550", EtwMath.optimal_size_level_threshold(100, 5.5))
111
+ assert(!EtwMath.optimal_size_level_threshold(-1, -1))
112
+ end
113
+
114
+ def test_optimal_multi
115
+ assert_equal("100", EtwMath.optimal_multi(550, 5.5))
116
+ assert(!EtwMath.optimal_multi(-1, -1))
117
+ end
118
+
119
+ def test_size_level_cost
120
+ assert_equal("80", EtwMath.size_level_cost(2))
121
+ assert(!EtwMath.size_level_cost(-1))
122
+ end
123
+
124
+ def test_walk_level_cost
125
+ assert_equal("1,080", EtwMath.walk_level_cost(2))
126
+ assert(!EtwMath.walk_level_cost(-1))
127
+ end
128
+
129
+ def test_multi_level_cost
130
+ assert_equal("40,000", EtwMath.multi_level_cost(2))
131
+ assert(!EtwMath.multi_level_cost(-1))
132
+ end
133
+
134
+ def test_eat_level_cost
135
+ assert_equal("80,000", EtwMath.eat_level_cost(2))
136
+ assert(!EtwMath.eat_level_cost(-1))
137
+ end
138
+
139
+ def test_total_size_investment
140
+ assert_equal("30,240", EtwMath.total_size_investment(10))
141
+ assert(!EtwMath.total_size_investment(-1))
142
+ end
143
+
144
+ def test_total_walk_investment
145
+ assert_equal("408,240", EtwMath.total_walk_investment(10))
146
+ assert(!EtwMath.total_walk_investment(-1))
147
+ end
148
+
149
+ def test_total_multi_investment
150
+ assert_equal("15,120,000", EtwMath.total_multi_investment(10))
151
+ assert(!EtwMath.total_multi_investment(-1))
152
+ end
153
+
154
+ def test_total_eat_investment
155
+ assert_equal("30,240,000", EtwMath.total_eat_investment(10))
156
+ assert(!EtwMath.total_eat_investment(-1))
157
+ end
158
+
159
+ def test_total_upgrade_investment
160
+ assert_equal("237,475,190", EtwMath.total_upgrade_investment(83, 10, 15, 11))
161
+ assert_equal("5,474,602,884,855", EtwMath.total_upgrade_investment(1000, 400, 200, 75))
162
+ assert(!EtwMath.total_upgrade_investment(-1, -1, -1, -1))
163
+ end
164
+
165
+ def test_size_range_cost
166
+ assert_equal("28,000", EtwMath.size_range_cost(5, 10))
167
+ assert(!EtwMath.size_range_cost(-1, -1))
168
+ end
169
+
170
+ def test_walk_range_cost
171
+ assert_equal("378,000", EtwMath.walk_range_cost(5, 10))
172
+ assert(!EtwMath.walk_range_cost(-1, -1))
173
+ end
174
+
175
+ def test_multi_range_cost
176
+ assert_equal("14,000,000", EtwMath.multi_range_cost(5, 10))
177
+ assert(!EtwMath.multi_range_cost(-1, -1))
178
+ end
179
+
180
+ def test_eat_range_cost
181
+ assert_equal("28,000,000", EtwMath.eat_range_cost(5, 10))
182
+ assert(!EtwMath.eat_range_cost(-1, -1))
183
+ end
184
+
185
+ def test_small_bite_amount
186
+ assert_equal("20,300", EtwMath.small_bite_amount(505000, 100))
187
+ assert(!EtwMath.small_bite_amount(-1, -1))
188
+ end
189
+
190
+ def test_medium_bite_amount
191
+ assert_equal("30,600", EtwMath.medium_bite_amount(505000, 100))
192
+ assert(!EtwMath.medium_bite_amount(-1, -1))
193
+ end
194
+
195
+ def test_big_bite_amount
196
+ assert_equal("41,000", EtwMath.big_bite_amount(505000, 100))
197
+ assert(!EtwMath.big_bite_amount(-1, -1))
198
+ end
199
+
200
+ def test_small_bite_delta_multi
201
+ assert_equal("53", EtwMath.small_bite_delta_multi(9440, 10954))
202
+ assert(!EtwMath.small_bite_delta_multi(-1, -1))
203
+ end
204
+
205
+ def test_medium_bite_delta_multi
206
+ assert_equal("35", EtwMath.medium_bite_delta_multi(9440, 10954))
207
+ assert(!EtwMath.medium_bite_delta_multi(-1, -1))
208
+ end
209
+
210
+ def test_big_bite_delta_multi
211
+ assert_equal("27", EtwMath.big_bite_delta_multi(9440, 10954))
212
+ assert(!EtwMath.big_bite_delta_multi(-1, -1))
213
+ end
214
+
215
+ def test_small_first_bite_multi
216
+ assert_equal("94", EtwMath.small_first_bite_multi(270))
217
+ assert(!EtwMath.small_first_bite_multi(-1))
218
+ end
219
+
220
+ def test_medium_first_bite_multi
221
+ assert_equal("63", EtwMath.medium_first_bite_multi(270))
222
+ assert(!EtwMath.medium_first_bite_multi(-1))
223
+ end
224
+
225
+ def test_big_first_bite_multi
226
+ assert_equal("47", EtwMath.big_first_bite_multi(270))
227
+ assert(!EtwMath.big_first_bite_multi(-1))
228
+ end
229
+
230
+ def test_time_to_max
231
+ assert_equal("00d:00h:04m:49s", EtwMath.time_to_max(565, 101))
232
+ assert(!EtwMath.time_to_max(-1, -1))
233
+ end
234
+
235
+ def test_time_to_max_small
236
+ assert_equal("00d:00h:02m:45s", EtwMath.time_to_max_small(140, 31))
237
+ assert(!EtwMath.time_to_max_small(-1, -1))
238
+ end
239
+ end
metadata CHANGED
@@ -1,28 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etw_math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lazy Villain
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-10-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Calculate the cost of upgrades, another player's multiplier, and more.
14
- email:
15
13
  executables: []
16
14
  extensions: []
17
15
  extra_rdoc_files: []
18
16
  files:
19
17
  - example.rb
20
18
  - lib/etw_math.rb
19
+ - test.rb
21
20
  homepage: https://github.com/LazyAntihero/etw_math
22
21
  licenses:
23
22
  - BSD-2-Clause
24
23
  metadata: {}
25
- post_install_message:
26
24
  rdoc_options: []
27
25
  require_paths:
28
26
  - lib
@@ -30,15 +28,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
30
28
  requirements:
31
29
  - - ">="
32
30
  - !ruby/object:Gem::Version
33
- version: '0'
31
+ version: 2.7.0
34
32
  required_rubygems_version: !ruby/object:Gem::Requirement
35
33
  requirements:
36
34
  - - ">="
37
35
  - !ruby/object:Gem::Version
38
36
  version: '0'
39
37
  requirements: []
40
- rubygems_version: 3.0.3.1
41
- signing_key:
38
+ rubygems_version: 3.6.9
42
39
  specification_version: 4
43
40
  summary: Various mathematical formulas for Roblox - Eat the World (ETW)
44
41
  test_files: []