Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jullija committed Jun 22, 2023
1 parent d37cbdc commit c33530b
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion shipsgame/.idea/modules/shipsgame-build.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shipsgame/.idea/modules/shipsgame.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions shipsgame/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
["sbt.Task[scala.collection.Seq[java.nio.file.Path]]",["C:\\Users\\Julija\\Desktop\\lala\\shipsgame\\project\\target\\scala-2.12\\sbt-1.0\\zinc\\inc_compile_2.12.zip"]]
["sbt.Task[scala.collection.Seq[java.nio.file.Path]]",["E:\\Studia\\2_rok\\semestr4\\Scala\\Battleship\\shipsgame\\project\\target\\scala-2.12\\sbt-1.0\\zinc\\inc_compile_2.12.zip"]]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes
E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[debug] Created transactional ClassFileManager with tempDir = C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak
[debug] Created transactional ClassFileManager with tempDir = E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak
[debug] About to delete class files:
[debug] We backup class files:
[debug] Created transactional ClassFileManager with tempDir = C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak
[debug] Removing the temporary directory used for backing up class files: C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak
[debug] Created transactional ClassFileManager with tempDir = E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak
[debug] Removing the temporary directory used for backing up class files: E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes.bak

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes
E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Users\Julija\Desktop\lala\shipsgame\project\target\scala-2.12\sbt-1.0\classes
E:\Studia\2_rok\semestr4\Scala\Battleship\shipsgame\project\target\scala-2.12\sbt-1.0\classes
9 changes: 5 additions & 4 deletions shipsgame/src/main/scala/Board.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package main.battleship

import main.battleship.Constants.SIZE

import scala.collection.mutable
import scala.math.abs
import main.battleship.ShipType.ShipType

class Board {
class Board{
var occupied = new mutable.HashSet[(Int, Int)]();
var size = 0;
var ships = new mutable.HashSet[Ship]();
var checked = new mutable.HashSet[(Int, Int)]();

Expand All @@ -26,8 +27,8 @@ class Board {
}

def printBoard(): Unit ={
for (i <- 0 until size){
for (j <- 0 until size){
for (i <- 0 until SIZE){
for (j <- 0 until SIZE){
if (occupied.contains((i, j))){
print("x")
}
Expand Down
1 change: 1 addition & 0 deletions shipsgame/src/main/scala/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package main.battleship
object Constants {
val ACQUIRED_POINTS = 5
val LOST_POINTS = 1
val SIZE = 10
}
36 changes: 36 additions & 0 deletions shipsgame/src/test/scala/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package test.scala

import main.battleship.ShipType.Type1
import main.battleship.{Board, ShipFactory}
import org.scalatest.funsuite.AnyFunSuite

class Test extends AnyFunSuite{

test("creatingShips"){
val shipFactory = new ShipFactory
val ship1 = shipFactory.createShip("Type1");
val ship2 = shipFactory.createShip("Type2");
val ship3 = shipFactory.createShip("Type3");
val ship4 = shipFactory.createShip("Type4");

assert(ship1.get.size === 5)
assert(ship2.get.size === 8)
assert(ship3.get.size === 3)
assert(ship4.get.size === 2)

}


test("addingOnBoard"){
var board = new Board
val shipFactory = new ShipFactory
board.addShip(2, 2, 6, 2, Type1)
assert(board.isEmpty() === false)
assert(board.tryAttack(4, 2) === true)
assert(board.tryAttack(7, 8) === false)
assert(board.occupied.contains(3, 2))
assert(board.alreadyChecked(4, 2) === true)

}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"{\"organization\":\"org.scala-lang\",\"name\":\"scala-library\",\"revision\":\"2.13.11\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{},\"crossVersion\":{\"type\":\"Disabled\"}}":{"value":{"$fields":["path","range"],"path":"C:\\Users\\Julija\\Desktop\\lala\\shipsgame\\build.sbt","range":{"$fields":["start","end"],"start":9,"end":10}},"type":"RangePosition"},"{\"organization\":\"org.scalatest\",\"name\":\"scalatest\",\"revision\":\"3.2.11\",\"configurations\":\"test\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{},\"crossVersion\":{\"type\":\"Binary\",\"prefix\":\"\",\"suffix\":\"\"}}":{"value":{"$fields":["path","range"],"path":"C:\\Users\\Julija\\Desktop\\lala\\shipsgame\\build.sbt","range":{"$fields":["start","end"],"start":9,"end":10}},"type":"RangePosition"}}
{"{\"organization\":\"org.scala-lang\",\"name\":\"scala-library\",\"revision\":\"2.13.11\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{},\"crossVersion\":{\"type\":\"Disabled\"}}":{"value":{"$fields":["path","range"],"path":"E:\\Studia\\2_rok\\semestr4\\Scala\\Battleship\\shipsgame\\build.sbt","range":{"$fields":["start","end"],"start":9,"end":10}},"type":"RangePosition"},"{\"organization\":\"org.scalatest\",\"name\":\"scalatest\",\"revision\":\"3.2.11\",\"configurations\":\"test\",\"isChanging\":false,\"isTransitive\":true,\"isForce\":false,\"explicitArtifacts\":[],\"inclusions\":[],\"exclusions\":[],\"extraAttributes\":{},\"crossVersion\":{\"type\":\"Binary\",\"prefix\":\"\",\"suffix\":\"\"}}":{"value":{"$fields":["path","range"],"path":"E:\\Studia\\2_rok\\semestr4\\Scala\\Battleship\\shipsgame\\build.sbt","range":{"$fields":["start","end"],"start":9,"end":10}},"type":"RangePosition"}}

Large diffs are not rendered by default.

0 comments on commit c33530b

Please sign in to comment.