<commit_before>package io.aigar.game

import org.scalatest._

class ResourcesSpec extends FlatSpec with Matchers {
  "Resources" should "spawn at the right quantity" in {
    val resources = new Resources(new Grid(0, 0))

    val state = resources.state

    state.regular should have size Regular.Max
    state.silver should have size Silver.Max
    state.gold should have size Gold.Max
  }

  it should "respawn resources when the quantity is minimal" in {
    val resources = new Resources(new Grid(0, 0))

    for(resourceType <- resources.resourceTypes){
      resourceType.positions = resourceType.positions.take(resourceType.min)
    }

    resources.update(List())

    for(resourceType <- resources.resourceTypes){
      resourceType.positions.length should be > resourceType.min
    }
  }

  it should "not respawn resources when the quantity is maximal" in {
    val resources = new Resources(new Grid(0, 0))

    for(resourceType <- resources.resourceTypes){
      resourceType.positions = List.fill(resourceType.max)(new Grid(0, 0).randomPosition)
    }

    resources.update(List())

    for(resourceType <- resources.resourceTypes){
      resourceType.positions.length should equal(resourceType.max)
    }
  }

  "Cell" should "increase its mass when eating regular or silver resources" in {
    val game = new Game(0, 1 to 15 toList)
    val resources = new Resources(game.grid)
    val cell = game.players.head.cells.head
    val initialMass = cell.mass

    resources.resourceTypes.head.reward(cell)

    cell.mass should be > initialMass
  }
}
<commit_msg>Adds test for detectCollisions<commit_after>package io.aigar.game

import com.github.jpbetz.subspace.Vector2
import org.scalatest._

class ResourcesSpec extends FlatSpec with Matchers {
  "Resources" should "spawn at the right quantity" in {
    val resources = new Resources(new Grid(0, 0))

    val state = resources.state

    state.regular should have size Regular.Max
    state.silver should have size Silver.Max
    state.gold should have size Gold.Max
  }

  it should "respawn when the quantity is minimal" in {
    val resources = new Resources(new Grid(0, 0))

    for(resourceType <- resources.resourceTypes){
      resourceType.positions = resourceType.positions.take(resourceType.min)
    }

    resources.update(List())

    for(resourceType <- resources.resourceTypes){
      resourceType.positions.length should be > resourceType.min
    }
  }

  it should "not respawn when the quantity is maximal" in {
    val resources = new Resources(new Grid(0, 0))

    for(resourceType <- resources.resourceTypes){
      resourceType.positions = List.fill(resourceType.max)(new Grid(0, 0).randomPosition)
    }

    resources.update(List())

    for(resourceType <- resources.resourceTypes){
      resourceType.positions.length should equal(resourceType.max)
    }
  }

  "Resource" should "be consumed on collision" in {
    val resource = new ResourceType(new Grid(0, 0), 0,0,5,10)
    val far = Vector2(1000f, 1000f)
    resource.positions = List(Vector2(10f,10f), far)
    val cell = new Cell(1)
    cell.position = Vector2(10f, 10f)
    val player = new Player(1, Vector2(10f, 10f))
    player.cells = List(cell)

    resource.detectCollisions(List(player))

    resource.positions should contain only far
  }

  it should "reward the cell and player accordingly" in {
    val resource = new ResourceType(new Grid(0, 0), 0, 0, 5, 10)
    val cell = new Cell(1)
    cell.mass = 1

    resource.reward(cell)

    cell.mass should equal(6)
  }
}

{'fraction_non_alphanumeric': 0.09631728045325778, 'fraction_numerical': 0.018130311614730877, 'mean_word_length': 3.424812030075188, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, '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': '131670', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1019, 'n_words': 305}