<commit_before>/*
 * Copyright 2016 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package services.onlinetesting.phase2

import config.Phase2ScheduleExamples._
import config.{ Phase2Schedule, Phase2TestsConfig }
import org.scalatestplus.play.PlaySpec

class ScheduleSelectorSpec extends PlaySpec {

  "get random schedule" should {
    "throw an exception when no schedules are configured" in {
      val selector = createSelector(List())

      intercept[IllegalArgumentException] {
        selector.getRandomSchedule
      }
    }

    "return a schedule" in {
      val schedules = List(DaroShedule, IradShedule, WardShedule)
      val selector = createSelector(schedules)
      val randomSchedules = 1 to 1000 map (_ => selector.getRandomSchedule)

      randomSchedules.distinct must contain theSameElementsAs schedules
    }
  }

  private def createSelector(schedules: List[Phase2Schedule]): ScheduleSelector = new ScheduleSelector {
    def testConfig = Phase2TestsConfig(1, schedules)<commit_msg>improve test naming<commit_after>/*
 * Copyright 2016 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package services.onlinetesting.phase2

import config.Phase2ScheduleExamples._
import config.{ Phase2Schedule, Phase2TestsConfig }
import org.scalatestplus.play.PlaySpec

class ScheduleSelectorSpec extends PlaySpec {

  "get random schedule" should {
    "throw an exception when no schedules are configured" in {
      val selector = createSelector(List())

      intercept[IllegalArgumentException] {
        selector.getRandomSchedule
      }
    }

    "return a schedule randomly" in {
      val schedules = List(DaroShedule, IradShedule, WardShedule)
      val selector = createSelector(schedules)
      val randomSchedules = 1 to 1000 map (_ => selector.getRandomSchedule)

      randomSchedules.distinct must contain theSameElementsAs schedules
    }
  }

  private def createSelector(schedules: List[Phase2Schedule]): ScheduleSelector = new ScheduleSelector {
    def testConfig = Phase2TestsConfig(1, schedules)
{'fraction_non_alphanumeric': 0.06836504353434376, 'fraction_numerical': 0.012899064817800709, 'mean_word_length': 3.9552715654952078, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3434593', 'n_tokens_mistral': 831, 'n_tokens_neox': 770, 'n_words': 304}