<commit_before># tests the singleton case of summary collections, where there is only one subset in the collection
# tests for the multiple case, where there are multiple subsets in the collection, are currently in SummaryCollectionMultipleTest

require 'test_helper'
require 'unit/report/report_test_helper'

class Report::SummaryCollectionSingleTest < ActiveSupport::TestCase
  test "summary should contain question type" do
    prepare_form_and_collection('integer', [0])
    assert_equal('integer', first_summary.qtype.name)
  end

  test "observer integer summary should be correct" do
    #prepare_form_and_collection('integer', [10, 7, 6, 1, 1])
    prepare_form('integer', [10, 7, 6, 1, 1])

    observer = FactoryGirl.create(:user, :role_name => :observer)
    observer.current_mission = get_mission
    [10, 7, 6, 1, 1].each{|a| FactoryGirl.create(:response, :form => @form, :_answers => [a], :user => observer)}

    ability = Ability.new(observer)
    @collection = Report::SummaryCollectionBuilder.new(@form.questionings, nil, ability).build

    assert_equal({:mean => 5.0, :max => 10, :min => 1}, headers_and_items(:stat, :stat))<commit_msg>fixed bug in summary collection test<commit_after># tests the singleton case of summary collections, where there is only one subset in the collection
# tests for the multiple case, where there are multiple subsets in the collection, are currently in SummaryCollectionMultipleTest

require 'test_helper'
require 'unit/report/report_test_helper'

class Report::SummaryCollectionSingleTest < ActiveSupport::TestCase
  test "summary should contain question type" do
    prepare_form_and_collection('integer', [0])
    assert_equal('integer', first_summary.qtype.name)
  end

  test "observer integer summary should be correct" do
    #prepare_form_and_collection('integer', [10, 7, 6, 1, 1])
    prepare_form('integer', [10, 7, 6, 1, 1])

    observer = FactoryGirl.create(:user, :role_name => :observer)
    observer.current_mission = get_mission
    [10, 7, 6, 1, 1].each{|a| FactoryGirl.create(:response, :form => @form, :_answers => [a], :user => observer)}

    @collection = Report::SummaryCollectionBuilder.new(@form.questionings, nil, :restrict_to_user => observer).build

    assert_equal({:mean => 5.0, :max => 10, :min => 1}, headers_and_items(:stat, :stat))
{'fraction_non_alphanumeric': 0.12020680741059887, 'fraction_numerical': 0.02068074105988798, 'mean_word_length': 5.3791208791208796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4037411', 'n_tokens_mistral': 720, 'n_tokens_neox': 656, 'n_words': 213}