-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cricket Players Unique Name #27464
Closed
Closed
Cricket Players Unique Name #27464
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38582a8
Create a map of cricker players id and unique name
ioannakok 993b69e
Add unit tests for PlayerNames.uniqueNames
ioannakok 22bf328
PlayerNamesTest
ioannakok a7804a1
Pass variables
ioannakok 4081b7b
Get catcher and bowler ids
ioannakok 4102e0d
Add descriptionWithUniqueNames method
ioannakok 12a10ae
Call descriptionWithUniqueNames
ioannakok c694556
Substitute cricket match description for certain dismissal types
ioannakok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cricket.feed | ||
|
||
import cricketModel.Player | ||
|
||
object PlayerNames { | ||
|
||
def uniqueNames(players: List[Player]) = (for { | ||
playersGroupedByName <- players.groupBy(_.lastName).values | ||
player <- playersGroupedByName | ||
} yield { | ||
player.id -> { if (playersGroupedByName.size > 1) s"${player.firstName} ${player.lastName}" else player.lastName } | ||
}).toMap | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
sport/test/cricket/feed/CricketPaDeserialisationTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cricket.feed | ||
|
||
import org.apache.pekko.actor.{ActorSystem => PekkoActorSystem} | ||
import conf.cricketPa.PaFeed | ||
import org.scalatest.{BeforeAndAfterAll, DoNotDiscover} | ||
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import test.{ | ||
ConfiguredTestSuite, | ||
WithMaterializer, | ||
WithTestApplicationContext, | ||
WithTestExecutionContext, | ||
WithTestWsClient, | ||
} | ||
|
||
@DoNotDiscover class CricketPaDeserialisationTest | ||
extends AnyFlatSpec | ||
with Matchers | ||
with ConfiguredTestSuite | ||
with BeforeAndAfterAll | ||
with WithMaterializer | ||
with WithTestWsClient | ||
with WithTestApplicationContext | ||
with WithTestExecutionContext | ||
with ScalaFutures | ||
with IntegrationPatience { | ||
val actorSystem = PekkoActorSystem() | ||
val paFeed = new PaFeed(wsClient, actorSystem, materializer) | ||
|
||
whenReady(paFeed.getMatch("39145392-3f2e-8022-35f3-eac0b0654610")) { cricketMatch => | ||
{ | ||
cricketMatch.innings.head.batters.head.howOut shouldBe "" | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cricket.feed | ||
|
||
import cricketModel.Player | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class PlayerNamesTest extends AnyFlatSpec with Matchers { | ||
|
||
"uniqueNames" should "be determined by lastName if players have different last names" in { | ||
val player1 = Player( | ||
id = "ae5e0dbf-d6af-70ec-76ef-1f8e83230405", | ||
name = "Asitha Fernando", | ||
firstName = "Asitha", | ||
lastName = "Fernando", | ||
initials = "A M", | ||
) | ||
val player2 = Player( | ||
id = "c32cd9c7-d38a-93e7-e874-f5f4a5197812", | ||
name = "Dimuth Karunaratne", | ||
firstName = "Frank", | ||
lastName = "Karunaratne", | ||
initials = "F D M", | ||
) | ||
val player3 = Player( | ||
id = "b96e5130-0348-9659-e3c6-ba887f306eeb", | ||
name = "Kusal Mendis", | ||
firstName = "Balapuwaduge", | ||
lastName = "Mendis", | ||
initials = "B K G", | ||
) | ||
|
||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Fernando") | ||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Mendis") | ||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Karunaratne") | ||
} | ||
|
||
it should "be determined by full name and lastName if players have the same last name" in { | ||
val player1 = Player( | ||
id = "ae5e0dbf-d6af-70ec-76ef-1f8e83230405", | ||
name = "Asitha Fernando", | ||
firstName = "Asitha", | ||
lastName = "Fernando", | ||
initials = "A M", | ||
) | ||
val player2 = Player( | ||
id = "c32cd9c7-d38a-93e7-e874-f5f4a5197812", | ||
name = "Dimuth Karunaratne", | ||
firstName = "Frank", | ||
lastName = "Karunaratne", | ||
initials = "F D M", | ||
) | ||
val player3 = Player( | ||
id = "d29c8d1c-29b4-517e-5b62-1277065801b2", | ||
name = "Nishan Madushka", | ||
firstName = "Kottasinghakkarage", | ||
lastName = "Fernando", | ||
initials = "K N M", | ||
) | ||
|
||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Asitha Fernando") | ||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Karunaratne") | ||
PlayerNames.uniqueNames(List(player1, player2, player3)).values.toList should contain("Kottasinghakkarage Fernando") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is WIP so I added
@DoNotDiscover
to keep the build green. At the moment it's failing with error:We will probably want to change the test anyway and use test data instead of hitting the PA API.
Examples of xml sports test data in the codebase:
https://github.com/guardian/frontend/tree/main/admin/test/football/testdata
https://github.com/guardian/frontend/blob/main/sport/test/resources/rugby/feed/live-scores.xml