Housekeeping

This commit is contained in:
Ralf Comtesse 2025-10-06 08:22:51 +02:00
parent 5ed38a6ae3
commit 639c709c99
6 changed files with 59 additions and 60 deletions

View File

@ -7,12 +7,11 @@ lazy val root = project
version := "1.0",
scalaVersion := scala3Version,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"com.approvaltests" % "approvaltests" % "25.4.3" % Test,
"junit" % "junit" % "4.13.2",
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"com.approvaltests" % "approvaltests" % "25.4.3" % Test,
"junit" % "junit" % "4.13.2",
"com.github.sbt.junit" % "jupiter-interface" % "0.15.1" % Test,
"org.junit.jupiter" % "junit-jupiter" % "6.0.0" % Test
"org.junit.jupiter" % "junit-jupiter" % "6.0.0" % Test
),
testOptions += Tests.Argument(TestFrameworks.JUnit)
testOptions += Tests.Argument(TestFrameworks.JUnit)
)

View File

@ -1,5 +1,5 @@
package com.gildedrose
case class Item(val name: String, var sellIn: Int, var quality: Int) {
case class Item(name: String, var sellIn: Int, var quality: Int) {
}

View File

@ -3,16 +3,16 @@ package com.gildedrose
object Main {
def main(args: Array[String]): Unit = {
val items = Array[Item](
new Item("+5 Dexterity Vest", 10, 20),
new Item("Aged Brie", 2, 0),
new Item("Elixir of the Mongoose", 5, 7),
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
Item("+5 Dexterity Vest", 10, 20),
Item("Aged Brie", 2, 0),
Item("Elixir of the Mongoose", 5, 7),
Item("Sulfuras, Hand of Ragnaros", 0, 80),
Item("Sulfuras, Hand of Ragnaros", -1, 80),
Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
// this conjured item does not work properly yet
new Item("Conjured Mana Cake", 3, 6)
Item("Conjured Mana Cake", 3, 6)
)
val app = new GildedRose(items)

View File

@ -0,0 +1,38 @@
package com.gildedrose
import org.approvaltests.Approvals
import org.approvaltests.reporters.DiffReporter
import org.approvaltests.reporters.UseReporter
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@UseReporter(Array(classOf[DiffReporter]))
class GildedRoseApprovalTest {
@Test
def foo(): Unit = {
val items: Array[Item] = Array(Item("foo", 0, 0))
val app: GildedRose = new GildedRose(items)
app.updateQuality()
Approvals.verifyAll("Items", items)
}
@Test
def thirtyDays(): Unit = {
val fakeoutput: ByteArrayOutputStream = new ByteArrayOutputStream()
System.setOut(new PrintStream(fakeoutput))
System.setIn(new ByteArrayInputStream("a\n".getBytes()))
val args: Array[String] = Array("30")
TexttestFixture.main(args)
val output: String = fakeoutput.toString()
Approvals.verify(output)
}
}

View File

@ -1,38 +0,0 @@
package com.gildedrose;
import org.approvaltests.Approvals
import org.approvaltests.reporters.DiffReporter
import org.approvaltests.reporters.UseReporter
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@UseReporter(Array(classOf[DiffReporter]))
class GildedRoseApprovalTestInScala {
@Test
def foo(): Unit = {
val items: Array[Item] = Array(new Item("foo", 0, 0))
val app: GildedRose = new GildedRose(items);
app.updateQuality();
Approvals.verifyAll("Items", items);
}
@Test
def thirtyDays(): Unit = {
val fakeoutput: ByteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(fakeoutput));
System.setIn(new ByteArrayInputStream("a\n".getBytes()));
val args: Array[String] = Array("30")
TexttestFixture.main(args);
val output: String = fakeoutput.toString();
Approvals.verify(output);
}
}

View File

@ -4,10 +4,10 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class GildedRoseTest extends AnyFlatSpec with Matchers {
it should "foo" in {
val items = Array[Item](new Item("foo", 0, 0))
val app = new GildedRose(items)
app.updateQuality()
app.items(0).name should equal ("fixme")
}
it should "foo" in {
val items = Array[Item](Item("foo", 0, 0))
val app = new GildedRose(items)
app.updateQuality()
app.items(0).name should equal("fixme")
}
}