Sha256: 37b9d9b0c94c294cb5e0bf4c453ea47f33331ebd3fa18947525e6f95a6ef1ac9

Contents?: true

Size: 1.14 KB

Versions: 62

Compression:

Stored size: 1.14 KB

Contents

require 'test_helper'

module Workarea
  module Metrics
    class CalculatePercentilesTest < TestCase
      def test_simple_data
        create_data(*0..99)
        results = find_results

        assert_equal(100, results.size)
        assert_equal(1, results['1'])
        assert_equal(99, results['99'])
      end

      def test_smaller_data
        create_data(15, 20, 25, 40, 50)
        results = find_results

        assert_equal(100, results.size)
        assert_equal(15, results['5'])
        assert_equal(20, results['30'])
        assert_equal(25, results['40'])
        assert_equal(25, results['50'])
        assert_equal(50, results['99'])
      end

      def test_clean_data
        create_data(12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48)
        assert_equal(36, find_results['65'])
      end

      private

      def create_data(*values)
        values.each do |value|
          ProductForLastWeek.create!(product_id: value, views: value)
        end
      end

      def find_results
        CalculatePercentiles
          .new(ProductForLastWeek.collection, :views)
          .results
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.26 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.45 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.25 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.23 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.44 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.22 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.43 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.21 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.42 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.20 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.41 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.19 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.40 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.18 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.39 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.17 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.38 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.5.16 test/models/workarea/metrics/calculate_percentiles_test.rb
workarea-core-3.4.37 test/models/workarea/metrics/calculate_percentiles_test.rb