<commit_before>package assigner

import org.json4s.jackson.Serialization._
import org.json4s.{DefaultFormats, Formats}
import org.scalatra.test.specs2._

class ServletSpec extends MutableScalatraSpec {

  // Sets up automatic case class to JSON output serialization, required by
  // the JValueResult trait.
  protected implicit val jsonFormats: Formats = DefaultFormats
  addServlet(classOf[Servlet], "/*")

  "POST /run on Servlet with id = 1" should {
    "return status 200 and start the algorithm the first time and says its still running the second" in {
      val course = initPost(1)
      val json: String = write(course)

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm successfully started"
      }

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm is still running"
      }

      get("/finished/1") {
        status must_== 200
        body must_== "Algorithm is still running"
      }
    }
  }

  "POST /run on Servlet with id = 2" should {
    "return status 200 and body = Algorithm successfully started!" in {
      val course = initPost(2)
      val json: String = write(course)

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm successfully started"
      }
    }
  }

  def initPost(id: Int): Course = {
    val students = Set[Student](
      Student(id = 0, name = "Student 0", mandatory = true, skills = Map("1" -> 5, "2" -> 3, "3" -> 4),
        preferences = List(2, 1, 0), friends = Set(4)),
      Student(id = 1, name = "Student 1", mandatory = true, skills = Map("1" -> 1, "2" -> 5, "3" -> 2),
        preferences = List(1, 0, 2), friends = Set()),
      Student(id = 2, name = "Student 2", mandatory = true, skills = Map("1" -> 4, "2" -> 5, "3" -> 3),
        preferences = List(0, 2, 1), friends = Set()),
      Student(id = 3, name = "<NAME>", mandatory = true, skills = Map("1" -> 2, "2" -> 4, "3" -> 5),
        preferences = List(0, 1, 2), friends = Set(1,2,4,5,6,7,8,9)),
      Student(id = 4, name = "<NAME>", mandatory = true, skills = Map("1" -> 4, "2" -> 4, "3" -> 3),
        preferences = List(2, 1, 0), friends = Set()),
      Student(id = 5, name = "<NAME>", mandatory = true, skills = Map("1" -> 3, "2" -> 3, "3" -> 3),
        preferences = List(1, 2, 0), friends = Set(3, 8)),<commit_msg>Added test to check for a course that doesn't exists<commit_after>package assigner

import org.json4s.jackson.Serialization._
import org.json4s.{DefaultFormats, Formats}
import org.scalatra.test.specs2._

class ServletSpec extends MutableScalatraSpec {

  // Sets up automatic case class to JSON output serialization, required by
  // the JValueResult trait.
  protected implicit val jsonFormats: Formats = DefaultFormats
  addServlet(classOf[Servlet], "/*")

  "POST /run on Servlet with id = 1" should {
    "return status 200 and start the algorithm the first time and says its still running the second" in {
      val course = initPost(1)
      val json: String = write(course)

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm successfully started"
      }

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm is still running"
      }

      get("/finished/1") {
        status must_== 200
        body must_== "Algorithm is still running"
      }
    }
  }

  "POST /run on Servlet with id = 2" should {
    "return status 200 and body = Algorithm successfully started!" in {
      val course = initPost(2)
      val json: String = write(course)

      post("/run", json) {
        status must_== 200
        body must_== "Algorithm successfully started"
      }
    }
  }

  "Get /finished/3" should {
    "return status 200 say the course is not known" in {
      get("/finished/3") {
        status must_== 200
        body must_== "Course is not known"
      }
    }
  }

  def initPost(id: Int): Course = {
    val students = Set[Student](
      Student(id = 0, name = "Student 0", mandatory = true, skills = Map("1" -> 5, "2" -> 3, "3" -> 4),
        preferences = List(2, 1, 0), friends = Set(4)),
      Student(id = 1, name = "<NAME>", mandatory = true, skills = Map("1" -> 1, "2" -> 5, "3" -> 2),
        preferences = List(1, 0, 2), friends = Set()),
      Student(id = 2, name = "Student 2", mandatory = true, skills = Map("1" -> 4, "2" -> 5, "3" -> 3),
        preferences = List(0, 2, 1), friends = Set()),
      Student(id = 3, name = "<NAME>", mandatory = true, skills = Map("1" -> 2, "2" -> 4, "3" -> 5),
        preferences = List(0, 1, 2), friends = Set(1,2,4,5,6,7,8,9)),
      Student(id = 4, name = "Student 4", mandatory = true, skills = Map("1" -> 4, "2" -> 4, "3" -> 3),
        preferences = List(2, 1, 0), friends = Set()),
      Student(id = 5, name = "Student 5", mandatory = true, skills = Map("1" -> 3, "2" -> 3, "3" -> 3),
        preferences = List(1, 2, 0), friends = Set(3, 8)),
{'fraction_non_alphanumeric': 0.1578200972447326, 'fraction_numerical': 0.0423419773095624, 'mean_word_length': 2.564620938628159, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 44, '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': '2481675', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1560, 'n_words': 546}