mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 15:50:13 +01:00
move tests to new directory
This commit is contained in:
parent
65859807ea
commit
0bc9b0397a
42 changed files with 23 additions and 32 deletions
84
test/models/pie_chart_data_test.rb
Normal file
84
test/models/pie_chart_data_test.rb
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../minimal_test_helper')
|
||||
require 'app/models/stats/pie_chart_data'
|
||||
require 'active_support/core_ext/string'
|
||||
|
||||
class Stats::PieChartDataTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
xx = { :stats => { :other_actions_label => '(other)' } }
|
||||
I18n.backend.store_translations(:xx, xx)
|
||||
I18n.locale = :xx
|
||||
end
|
||||
|
||||
def test_with_0_items
|
||||
data = Stats::PieChartData.new([], 'a chart', 50)
|
||||
|
||||
assert_equal [], data.values
|
||||
assert_equal [], data.labels
|
||||
assert_equal [], data.ids
|
||||
end
|
||||
|
||||
def test_with_less_than_10_items
|
||||
items = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6}
|
||||
]
|
||||
|
||||
data = Stats::PieChartData.new(items, 'a chart', 50)
|
||||
|
||||
assert_equal [12, 4, 9, 15, 23, 20, 5, 1, 7], data.values
|
||||
assert_equal ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"], data.labels
|
||||
assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9], data.ids
|
||||
end
|
||||
|
||||
def test_with_exactly_10_items
|
||||
items = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19}
|
||||
]
|
||||
|
||||
data = Stats::PieChartData.new(items, 'a chart', 50)
|
||||
|
||||
assert_equal [10, 3, 7, 12, 19, 16, 4, 0, 5, 18], data.values
|
||||
assert_equal ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"], data.labels
|
||||
assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], data.ids
|
||||
end
|
||||
|
||||
def test_with_more_than_10_items
|
||||
items = [
|
||||
{'id' => 1, 'name' => 'one', 'total' => 11},
|
||||
{'id' => 2, 'name' => 'two', 'total' => 4},
|
||||
{'id' => 3, 'name' => 'three', 'total' => 8},
|
||||
{'id' => 4, 'name' => 'four', 'total' => 13},
|
||||
{'id' => 5, 'name' => 'five', 'total' => 20},
|
||||
{'id' => 6, 'name' => 'six', 'total' => 17},
|
||||
{'id' => 7, 'name' => 'seven', 'total' => 5},
|
||||
{'id' => 8, 'name' => 'eight', 'total' => 1},
|
||||
{'id' => 9, 'name' => 'nine', 'total' => 6},
|
||||
{'id' => 10, 'name' => 'ten', 'total' => 19},
|
||||
{'id' => 11, 'name' => 'eleven', 'total' => 14}
|
||||
]
|
||||
|
||||
data = Stats::PieChartData.new(items, 'a chart', 50)
|
||||
|
||||
assert_equal [9, 3, 6, 11, 16, 14, 4, 0, 5, 27], data.values
|
||||
assert_equal ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "(other)"], data.labels
|
||||
assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, -1], data.ids
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue