Skip to content

Commit

Permalink
Migrate unit tests + fix pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBernard03 committed Jul 17, 2024
1 parent b93f104 commit 1bde8ec
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Find APK and AAB files
id: find_files
run: |
APK_PATH=$(find . -name "app-release.apk" | head -n 1)
AAB_PATH=$(find . -name "app-release.aab" | head -n 1)
APK_PATH=$(find . -name "composeApp-release.apk" | head -n 1)
AAB_PATH=$(find . -name "composeApp-release.aab" | head -n 1)
echo "APK_PATH=$APK_PATH" >> $GITHUB_ENV
echo "AAB_PATH=$AAB_PATH" >> $GITHUB_ENV
- name: Upload APK to Artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- name: Find APK and AAB files
id: find_files
run: |
APK_PATH=$(find . -name "app-release.apk" | head -n 1)
AAB_PATH=$(find . -name "app-release.aab" | head -n 1)
APK_PATH=$(find . -name "composeApp-release.apk" | head -n 1)
AAB_PATH=$(find . -name "composeApp-release.aab" | head -n 1)
echo "APK_PATH=$APK_PATH" >> $GITHUB_ENV
echo "AAB_PATH=$AAB_PATH" >> $GITHUB_ENV
- name: Upload APK to Artifacts
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Keystore
/composeApp/build
/composeApp/build
/iosApp/iosApp.xcodeproj/project.xcworkspace/xcuserdata
*.apk
/composeApp/release
4 changes: 4 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
815A0DB92C46431400F6328F /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815A0DB82C46431400F6328F /* HistoryView.swift */; };
8182F93E2C452E2000738D85 /* PlayersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8182F93D2C452E2000738D85 /* PlayersView.swift */; };
818520652C4665CB001BAB49 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 818520642C4665CB001BAB49 /* GameView.swift */; };
81C625722C47D48600CCDD39 /* NewGameSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81C625712C47D48600CCDD39 /* NewGameSheet.swift */; };
81EB95542C45B3B60039A5A7 /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB95532C45B3B60039A5A7 /* PlayerView.swift */; };
81EB95582C45B5130039A5A7 /* PlayerColorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81EB95572C45B5130039A5A7 /* PlayerColorExtensions.swift */; };
/* End PBXBuildFile section */
Expand All @@ -30,6 +31,7 @@
815A0DB82C46431400F6328F /* HistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryView.swift; sourceTree = "<group>"; };
8182F93D2C452E2000738D85 /* PlayersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersView.swift; sourceTree = "<group>"; };
818520642C4665CB001BAB49 /* GameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameView.swift; sourceTree = "<group>"; };
81C625712C47D48600CCDD39 /* NewGameSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGameSheet.swift; sourceTree = "<group>"; };
81EB95532C45B3B60039A5A7 /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = "<group>"; };
81EB95572C45B5130039A5A7 /* PlayerColorExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerColorExtensions.swift; sourceTree = "<group>"; };
AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,6 +135,7 @@
isa = PBXGroup;
children = (
818520642C4665CB001BAB49 /* GameView.swift */,
81C625712C47D48600CCDD39 /* NewGameSheet.swift */,
);
path = Game;
sourceTree = "<group>";
Expand Down Expand Up @@ -272,6 +275,7 @@
7555FF83242A565900829871 /* ContentView.swift in Sources */,
815A0DB72C46430800F6328F /* SettingsView.swift in Sources */,
8182F93E2C452E2000738D85 /* PlayersView.swift in Sources */,
81C625722C47D48600CCDD39 /* NewGameSheet.swift in Sources */,
818520652C4665CB001BAB49 /* GameView.swift in Sources */,
81EB95542C45B3B60039A5A7 /* PlayerView.swift in Sources */,
);
Expand Down
64 changes: 19 additions & 45 deletions iosApp/iosApp/Game/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ struct GameView: View {
.padding()
.multilineTextAlignment(.center)
} else {
List {
HStack {
Grid {
GridRow() {
ForEach(currentGame!.players, id:\.id){ player in
Text(player.name)
.onTapGesture {
print(player.name + " tapped")
}
}
}
Divider()
ForEach(currentGame!.rounds, id:\.id){ round in
GridRow {
Text(round.bid.name)
}
}

}
.padding(.top)
Spacer()
}
}
.navigationTitle("Partie en cours")
Expand All @@ -63,52 +73,16 @@ struct GameView: View {
.labelStyle(.iconOnly)
}
}

}
.sheet(isPresented: $showNewGameSheet) {
VStack(alignment: .leading, spacing: 12) {
Text("Nouvelle partie")
.font(.title2)
.padding()

Text("Sélectionner les joueurs à ajouter dans la partie")
.font(.title3)
.padding(.horizontal)

List(players, id: \.id) { player in
HStack(spacing: 12) {
Image(systemName: selectedPlayers.contains(player) ? "checkmark.circle.fill" : "circle")
.foregroundColor(selectedPlayers.contains(player) ? player.color.toColor() : .gray)
Text(player.name)
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if selectedPlayers.contains(player) {
selectedPlayers.remove(player)
} else {
selectedPlayers.insert(player)
}

}
}

Button(action: {
createGameUseCase.invoke(players: players) { result, _ in
if result?.isSuccess() ?? false {
currentGame = result?.getOrNull()
}
NewGameSheet(players: $players, selectedPlayers: $selectedPlayers) {
createGameUseCase.invoke(players: Array(selectedPlayers)) { result, _ in
if result?.isSuccess() ?? false {
currentGame = result?.getOrNull()
}

showNewGameSheet.toggle()
}) {
Text("Démarrer la partie")
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.disabled(selectedPlayers.isEmpty)
.padding([.horizontal, .bottom])

showNewGameSheet.toggle()
}
.onAppear {
getPlayersUseCase.invoke { result, _ in
Expand Down
57 changes: 57 additions & 0 deletions iosApp/iosApp/Game/NewGameSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// NewGameSheet.swift
// iosApp
//
// Created by Thomas Bernard on 17/07/2024.
// Copyright © 2024 orgName. All rights reserved.
//

import SwiftUI
import Shared

struct NewGameSheet: View {

@Binding var players : [PlayerModel]
@Binding var selectedPlayers : Set<PlayerModel>
var onCreateGame : () -> Void

var body: some View {
VStack(alignment: .leading, spacing: 12) {
Text("Nouvelle partie")
.font(.title2)
.padding()

Text("Sélectionner les joueurs à ajouter dans la partie")
.font(.title3)
.padding(.horizontal)

List(players, id: \.id) { player in
HStack(spacing: 12) {
Image(systemName: selectedPlayers.contains(player) ? "checkmark.circle.fill" : "circle")
.foregroundColor(selectedPlayers.contains(player) ? player.color.toColor() : .gray)
Text(player.name)
Spacer()
}
.contentShape(Rectangle())
.onTapGesture {
if selectedPlayers.contains(player) {
selectedPlayers.remove(player)
}
else {
selectedPlayers.insert(player)
}
}
}

Button(action: { onCreateGame() }) {
Text("Démarrer la partie")
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.disabled(selectedPlayers.isEmpty)
.padding([.horizontal, .bottom])
}

}
}
3 changes: 3 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ kotlin {
// Fixes RoomDB Unresolved reference 'instantiateImpl' in iosMain
kotlin.srcDir("build/generated/ksp/metadata")
}
commonTest.dependencies {
implementation(libs.kotlin.test)
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions shared/src/commonTest/kotlin/CalculateDefenderScoreUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import commons.calculateDefenderScore
import kotlin.test.Test
import kotlin.test.assertEquals

class CalculateDefenderScoreUnitTest {
@Test
fun calculateDefendersScoreOne(){
val takerScore = -80
val mateScore = -40
val defendersScore = calculateDefenderScore(takerScore + mateScore, numberOfDefenders = 3)

assertEquals(defendersScore, 40)
}

@Test
fun calculateDefendersScoreTwo(){
val takerScore = -160
val defendersScore = calculateDefenderScore(takerScore, numberOfDefenders = 4)

assertEquals(defendersScore, 40)
}

@Test
fun calculateDefendersScoreThree(){
val takerScore = -224
val defendersScore = calculateDefenderScore(takerScore, numberOfDefenders = 4)

assertEquals(56, defendersScore)
}
}
22 changes: 22 additions & 0 deletions shared/src/commonTest/kotlin/CalculatePartnerScoreUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import commons.calculatePartnerScore
import kotlin.test.Test
import kotlin.test.assertEquals

class CalculatePartnerScoreUnitTest {

@Test
fun calculatePartnerScoreSmallOne(){
val takerScore = -80
val partnerScore = calculatePartnerScore(takerScore)

assertEquals(partnerScore, -40)
}

@Test
fun calculatePartnerScoreGuardOne(){
val takerScore = 200
val partnerScore = calculatePartnerScore(takerScore)

assertEquals(partnerScore, 100)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import commons.calculateTakerScore
import domain.models.Bid
import domain.models.Oudler
import kotlin.test.Test
import kotlin.test.assertEquals

class CalculateTakerCalledHimSelfUnitTest {
@Test
fun calculateTakerCalledHimSelfOne(){
val points = 30
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf()

val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true)
assertEquals(-204, takerScore)
}

@Test
fun calculateTakerCalledHimSelfTwo(){
val points = 36
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf(Oudler.EXCUSE)

val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true)
assertEquals(-160, takerScore)
}


@Test
fun negativeScoreSmallZeroOudler(){
val points = 23
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf()

val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true)
assertEquals(-232, takerScore)
}

@Test
fun negativeScoreSmallOneOudler(){
val points = 27
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf(Oudler.PETIT)

val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true)
assertEquals(-196, takerScore)
}

@Test
fun negativeScoreGuardTwoOudler(){
val points = 38
val bid = Bid.GUARD
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE)

val takerScore = calculateTakerScore(points, bid, oudlers.size, calledHimSelf = true)
assertEquals(-224, takerScore)
}
}
59 changes: 59 additions & 0 deletions shared/src/commonTest/kotlin/CalculateTakerScoreUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import commons.calculateTakerScore
import domain.models.Bid
import domain.models.Oudler
import kotlin.test.Test
import kotlin.test.assertEquals

class CalculateTakerScoreUnitTest {
@Test
fun checkTakerPointSmallOne(){
val points = 57
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf()

val score = calculateTakerScore(points, bid, oudlers.size)

assertEquals(52, score)
}

@Test
fun checkTakerPointSmallTwo(){
val points = 24
val bid = Bid.SMALL
val oudlers : List<Oudler> = listOf()

val score = calculateTakerScore(points, bid, oudlers.size)
assertEquals(-114, score)
}


@Test
fun checkTakerPointGuardOne(){
val points = 61
val bid = Bid.GUARD
val oudlers : List<Oudler> = listOf(Oudler.EXCUSE)

val score = calculateTakerScore(points, bid, oudlers.size)
assertEquals(140, score)
}

@Test
fun checkTakerPointGuardWithoutOne(){
val points = 63
val bid = Bid.GUARD_WITHOUT
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE)

val score = calculateTakerScore(points, bid, oudlers.size)
assertEquals(376, score)
}

@Test
fun checkTakerPointGuardWithoutTwo(){
val points = 71
val bid = Bid.GUARD_WITHOUT
val oudlers : List<Oudler> = listOf(Oudler.PETIT, Oudler.EXCUSE, Oudler.GRAND)

val score = calculateTakerScore(points, bid, oudlers.size)
assertEquals(480, score)
}
}
Loading

0 comments on commit 1bde8ec

Please sign in to comment.