Merge pull request #601 from adampridmore/Adam2

Update scala project from scala 2 to scala 3
This commit is contained in:
Emily Bache 2025-03-17 09:59:21 +00:00 committed by GitHub
commit b3a0463bba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 14 deletions

View File

@ -1,3 +1,22 @@
# Gilded Rose starting position in Scala
# Gilded Rose starting position in Scala 3 scalatest
TODO: explain how to run this code
## Build the project
``` cmd
sbt compile
```
## Run the Gilded Rose Command-Line program
For e.g. 10 days:
``` cmd
sbt "run 10"
```
## Run all the unit tests
``` cmd
sbt test
```

View File

@ -1,8 +1,11 @@
name := "GildedRose"
val scala3Version = "3.6.4"
version := "1.0"
lazy val root = project
.in(file("."))
.settings(
name := "GildedRose",
version := "1.0",
scalaVersion := scala3Version,
scalaVersion := "2.13.1"
resolvers += DefaultMavenRepository
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.1" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % "test"
)

View File

@ -1 +1 @@
sbt.version=1.3.9
sbt.version=1.10.10

View File

@ -3,7 +3,7 @@ package com.gildedrose
class GildedRose(val items: Array[Item]) {
def updateQuality() {
def updateQuality() : Unit = {
for (i <- 0 until items.length) {
if (!items(i).name.equals("Aged Brie")
&& !items(i).name.equals("Backstage passes to a TAFKAL80ETC concert")) {
@ -55,4 +55,4 @@ class GildedRose(val items: Array[Item]) {
}
}
}
}
}

View File

@ -1,6 +1,6 @@
package com.gildedrose
object TexttestFixture {
object Main {
def main(args: Array[String]): Unit = {
val items = Array[Item](
new Item("+5 Dexterity Vest", 10, 20),
@ -14,8 +14,13 @@ object TexttestFixture {
// this conjured item does not work properly yet
new Item("Conjured Mana Cake", 3, 6)
)
val app = new GildedRose(items)
val days = if (args.length > 0) args(0).toInt + 1 else 2
System.out.println("OMGHAI!")
for (i <- 0 until days) {
System.out.println("-------- day " + i + " --------")
System.out.println("name, sellIn, quality")

View File

@ -3,11 +3,11 @@ package com.gildedrose
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class GildedRoseTest extends AnyFlatSpec with 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")
}
}
}