Skip to content

Commit e4466ee

Browse files
I will apply scalafmt formatting to your code.
I will run `sbt scalafmtAll` to format Scala source files and sbt files according to your project's .scalafmt.conf configuration. This will address formatting errors identified by the linting job in your GitHub Actions workflow.
1 parent 5cf4704 commit e4466ee

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

src/main/scala/JsonFormats.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import java.util.UUID
55
// Assuming Participant and Society are in the default package (as seen from ls output)
66

77
object JsonFormats {
8+
89
// Encoder for UUID
9-
implicit val uuidEncoder: Encoder[UUID] = Encoder.encodeString.contramap[UUID](_.toString)
10+
implicit val uuidEncoder: Encoder[UUID] =
11+
Encoder.encodeString.contramap[UUID](_.toString)
1012

1113
// Encoder for Participant[Boolean]
12-
implicit val participantEncoder: Encoder[Participant[Boolean]] = deriveEncoder[Participant[Boolean]]
14+
implicit val participantEncoder: Encoder[Participant[Boolean]] =
15+
deriveEncoder[Participant[Boolean]]
1316

1417
// Encoder for Society[Boolean]
15-
implicit val societyEncoder: Encoder[Society[Boolean]] = deriveEncoder[Society[Boolean]]
18+
implicit val societyEncoder: Encoder[Society[Boolean]] =
19+
deriveEncoder[Society[Boolean]]
1620
}

src/test/scala/UnitedWeStandAppTest.scala

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,60 @@ import JsonFormats._ // Your encoders
99

1010
class UnitedWeStandAppTest extends AnyFunSuite {
1111

12-
test("UnitedWeStandApp.runCycles output should be valid JSON and contain non-empty participants array") {
12+
test(
13+
"UnitedWeStandApp.runCycles output should be valid JSON and contain non-empty participants array"
14+
) {
1315
// Directly call runCycles and serialize, to avoid capturing stdout
1416
val society = UnitedWeStandApp.runCycles(cycleCount = 5) // Use a small cycle count for testing
1517
val jsonString = society.asJson.noSpaces
1618

1719
// 1. Check if the string is valid JSON
1820
val parsedJsonResult = parse(jsonString)
19-
assert(parsedJsonResult.isRight, s"Output should be valid JSON. Parsing error: ${parsedJsonResult.left.getOrElse("")}")
21+
assert(
22+
parsedJsonResult.isRight,
23+
s"Output should be valid JSON. Parsing error: ${parsedJsonResult.left.getOrElse("")}"
24+
)
2025

2126
// 2. Perform checks on the parsed JSON structure
22-
val json = parsedJsonResult.getOrElse(throw new RuntimeException("JSON parsing failed in test, this should not happen due to the assert above."))
27+
val json = parsedJsonResult.getOrElse(
28+
throw new RuntimeException(
29+
"JSON parsing failed in test, this should not happen due to the assert above."
30+
)
31+
)
2332

2433
// Check for the presence of the 'participants' array
2534
val participantsCursor = json.hcursor.downField("participants")
26-
assert(participantsCursor.succeeded, "JSON should contain a 'participants' field.")
35+
assert(
36+
participantsCursor.succeeded,
37+
"JSON should contain a 'participants' field."
38+
)
2739

2840
// Check if 'participants' is an array and is non-empty
2941
val participantsArray = participantsCursor.as[List[Json]]
30-
assert(participantsArray.isRight, "'participants' field should be an array.")
31-
assert(participantsArray.getOrElse(Nil).nonEmpty, "Participants array should not be empty.")
42+
assert(
43+
participantsArray.isRight,
44+
"'participants' field should be an array."
45+
)
46+
assert(
47+
participantsArray.getOrElse(Nil).nonEmpty,
48+
"Participants array should not be empty."
49+
)
3250

3351
// 3. Optionally, check structure of a participant (if needed, more detailed)
3452
val firstParticipantOpt = participantsArray.getOrElse(Nil).headOption
35-
assert(firstParticipantOpt.isDefined, "Participant array should have at least one participant.")
53+
assert(
54+
firstParticipantOpt.isDefined,
55+
"Participant array should have at least one participant."
56+
)
3657

3758
val firstParticipantJson = firstParticipantOpt.get
38-
assert(firstParticipantJson.hcursor.downField("uuid").as[String].isRight, "Participant should have a 'uuid' string field.")
39-
assert(firstParticipantJson.hcursor.downField("opinion").as[Boolean].isRight, "Participant should have an 'opinion' boolean field.")
59+
assert(
60+
firstParticipantJson.hcursor.downField("uuid").as[String].isRight,
61+
"Participant should have a 'uuid' string field."
62+
)
63+
assert(
64+
firstParticipantJson.hcursor.downField("opinion").as[Boolean].isRight,
65+
"Participant should have an 'opinion' boolean field."
66+
)
4067
}
4168
}

0 commit comments

Comments
 (0)