mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Refactor TimeSeries
artifacts (#651)
* Reindent TimeSeries classes * Fix spacing in time series tests * Remove trend tests where current is nil I think if we've gotten this far with a nil value for current, there's a data integrity problem. If we allow this, we'll have to be very defensive in our code. Best to raise and fix early. * Reindent Money class * Refactor TimeSeries artifacts * Use as_json in TimeSeries * Bring back tests for trends where current is nil * Bring back trend test * Correctly enumerate trend test * Use favorable_direction for trend_styles helper * Make trend public in TimeSeries::Value * Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots * Clean up TimeSeries::Trend * Skip trend values same class validations if any values are nil * Refactor Money * Remove object parsing in TimeSeries::Value We're only every passing hashes
This commit is contained in:
parent
fe2a2ac3f9
commit
fc3ade392a
9 changed files with 258 additions and 206 deletions
|
@ -7,6 +7,7 @@ class TimeSeries::TrendTest < ActiveSupport::TestCase
|
|||
assert_equal Money.new(50), trend.value
|
||||
assert_equal 100.0, trend.percent
|
||||
end
|
||||
|
||||
test "up" do
|
||||
trend = TimeSeries::Trend.new(current: 100, previous: 50)
|
||||
assert_equal "up", trend.direction
|
||||
|
@ -19,8 +20,8 @@ class TimeSeries::TrendTest < ActiveSupport::TestCase
|
|||
|
||||
test "flat" do
|
||||
trend1 = TimeSeries::Trend.new(current: 100, previous: 100)
|
||||
trend3 = TimeSeries::Trend.new(current: 100, previous: nil)
|
||||
trend2 = TimeSeries::Trend.new(current: nil, previous: nil)
|
||||
trend2 = TimeSeries::Trend.new(current: 100, previous: nil)
|
||||
trend3 = TimeSeries::Trend.new(current: nil, previous: nil)
|
||||
assert_equal "flat", trend1.direction
|
||||
assert_equal "flat", trend2.direction
|
||||
assert_equal "flat", trend3.direction
|
||||
|
@ -39,7 +40,7 @@ class TimeSeries::TrendTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "empty" do
|
||||
trend =TimeSeries::Trend.new
|
||||
trend = TimeSeries::Trend.new(current: nil, previous: nil)
|
||||
assert_equal "flat", trend.direction
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue