Skip to content
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

Fix/logic of city that matches manager expectations #80

Open
wants to merge 130 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
a49cf8e
update gitignore to delete idea folder
AmeerAmjed Feb 7, 2023
46fe840
add fake data
mosayed01 Feb 9, 2023
c9362c5
add test cases for cheapest banana price
mosayed01 Feb 9, 2023
ccc6037
add implementation for cheapest banana price
mosayed01 Feb 9, 2023
32c7ac1
refactor: rename class cheapest banana price
mosayed01 Feb 9, 2023
52ac2e0
add fake data
Feb 9, 2023
0a93ebe
add test cases for matched city
Feb 9, 2023
ac6bc35
add fake data
Ethaar7 Feb 9, 2023
4b9f576
add test cases
Ethaar7 Feb 9, 2023
f31f887
update misspell countries names
TarekIdrees Feb 9, 2023
0f1eae0
first implementation of execute function
TarekIdrees Feb 9, 2023
4a52911
add implementation test to actual code
Ethaar7 Feb 9, 2023
b61d6e1
update version review
Abanoub-Nagy Feb 10, 2023
d56567e
add enum class in package
Ethaar7 Feb 10, 2023
79c8049
apply the required changes in the review and improve Option to Bedroo…
Ethaar7 Feb 10, 2023
a732164
Merge remote-tracking branch 'origin/feature/city_has_the_highest_dif…
Ethaar7 Feb 10, 2023
5234893
improve Option to BedroomOption as required changes in the review
Ethaar7 Feb 10, 2023
5f5e975
Merge remote-tracking branch 'origin/feature/city_has_the_highest_dif…
Ethaar7 Feb 10, 2023
3dcae3e
update version review
Abanoub-Nagy Feb 10, 2023
2d73e57
change return type from empty string to null in case of the countries…
Feb 10, 2023
99622e5
handle the case of countries names
Feb 10, 2023
f3bc9cf
add fake data and test cases
davidsamuelx Feb 10, 2023
db21962
update new version review
Abanoub-Nagy Feb 10, 2023
0517997
improve code
AmeerAmjed Feb 10, 2023
24e0577
improve code
AmeerAmjed Feb 10, 2023
9524918
complete the logic of feature
TarekIdrees Feb 10, 2023
a2ec718
improve fake data and test cases
davidsamuelx Feb 10, 2023
80ebd39
add implementation for cheapest city internet
davidsamuelx Feb 10, 2023
56e0b5c
add two test case
Abanoub-Nagy Feb 10, 2023
d965a42
improve logic of feature
Abanoub-Nagy Feb 10, 2023
9e7d460
improve code to be readable
Ethaar7 Feb 10, 2023
683fc83
add test case for best city interactor
Feb 10, 2023
5c81c52
create GetCitiesAverageSalary class
Ashraf-El-Fallah Feb 11, 2023
ba43931
add test cases for average salaries
Ashraf-El-Fallah Feb 11, 2023
4192cf2
add fake data source
Ashraf-El-Fallah Feb 11, 2023
3f5bbf9
make the code more readable by rename naming of variables and functions
Feb 11, 2023
3595ca7
improve code to be readable
davidsamuelx Feb 11, 2023
cb160ff
rename test case and delete unnecessary dependency
davidsamuelx Feb 11, 2023
b1deb1c
complete tests
Feb 11, 2023
3c61e63
Delete FakeDataSource.kt
Ali873-debug Feb 11, 2023
02d7c85
complete Implementation
Feb 11, 2023
ef5e92e
apply kotlin scope functions
TarekIdrees Feb 11, 2023
c091e0e
improve code
Feb 11, 2023
a8a8483
improve code phase two
Feb 11, 2023
95a401e
improve code to be short and readable
AmeerAmjed Feb 11, 2023
cfe53fc
initialize classes
Feb 11, 2023
b2c1a41
add fake data
Feb 11, 2023
42873e8
add test cases for average fruits and vegetabls
Feb 11, 2023
6606ac5
complete execute function
Feb 11, 2023
c7e1a13
fix expected data in test class
Ali873-debug Feb 11, 2023
477ba5d
add fake data
Ali873-debug Feb 11, 2023
23b891d
implement execute function for get cities average salary
Ali873-debug Feb 11, 2023
de6a255
Merge remote-tracking branch 'origin/feature/cities_average_salary' i…
Ali873-debug Feb 11, 2023
8f979f1
change toFormalCase function name to toChangeFormatCityName to be rea…
AmeerAmjed Feb 12, 2023
9456741
improve execute function
Feb 12, 2023
6e5c1cf
add new test case
Ali873-debug Feb 12, 2023
2d91220
improve code readability
TarekIdrees Feb 12, 2023
8dd1bd8
change exception to illegal argument exception
Ali873-debug Feb 12, 2023
6c4934b
add new test case and improve logic code
davidsamuelx Feb 12, 2023
69a568d
Merge remote-tracking branch 'origin/feature/cheapest_city_internet' …
davidsamuelx Feb 12, 2023
d0f235f
improve code to be readable
Ethaar7 Feb 12, 2023
377bf3b
Merge branch 'feature/city_that_match_manager_expectations' into develop
AmeerAmjed Feb 12, 2023
168feae
add return city
abdellahtachouchout Feb 12, 2023
5d80830
clean up
AmeerAmjed Feb 12, 2023
830e5b2
frist commit
khaledeid1k Feb 12, 2023
ba10673
Merge remote-tracking branch 'origin/develop' into develop
khaledeid1k Feb 12, 2023
21523e5
TopTenCountriesTaxes class with initial test class.
Feb 12, 2023
b098fa0
improve some code
Feb 12, 2023
7111794
Merge branch 'feature/average_fruits_vegetables' into develop
AmeerAmjed Feb 12, 2023
bb9bc3e
Merge branch 'feature/city_has_the_highest_different' into develop
AmeerAmjed Feb 13, 2023
b413df9
change handel fake data to create multi case in test case
AmeerAmjed Feb 13, 2023
4f4d4e6
Merge branch 'develop' into feature/cheapest_city_internet
AmeerAmjed Feb 13, 2023
da5b2d0
refactor fake data
AmeerAmjed Feb 13, 2023
6f62f45
improve code and handel nullability salaries
AmeerAmjed Feb 13, 2023
eac887d
TopTenCountriesTaxes class the null pointer exception solved.
Feb 13, 2023
cdec55c
improve code
khaledeid1k Feb 13, 2023
84daf15
add test without logic
Feb 13, 2023
98fef9d
add logic
Feb 13, 2023
2f6ae6d
create sub functions
Feb 13, 2023
9f345e5
improve code and add comments to function
khaledeid1k Feb 13, 2023
1e97412
Merge remote-tracking branch 'origin/develop' into feature/cheapest_a…
khaledeid1k Feb 13, 2023
67816fb
refactoring fake datasource
khaledeid1k Feb 13, 2023
d65bf8f
Clean up
khaledeid1k Feb 13, 2023
d2398ea
Merge branch 'develop' into feature/cities_average_salary
AmeerAmjed Feb 13, 2023
4be3f93
refactor fake data
AmeerAmjed Feb 13, 2023
e6e29f7
add test case
AmeerAmjed Feb 13, 2023
f233eea
add fake data
AmeerAmjed Feb 13, 2023
345fca7
delete file duplicated file
AmeerAmjed Feb 13, 2023
d3c6774
Merge remote-tracking branch 'origin/feature/best_fashion_shopping_ci…
AmeerAmjed Feb 13, 2023
921a635
implement feature get best cities for fashion shopping
AmeerAmjed Feb 13, 2023
32407a0
Delete FakeDataSource.kt
AmeerAmjed Feb 14, 2023
a680681
Delete FakeDataSource.kt
AmeerAmjed Feb 14, 2023
984a72b
improve fake data and edit test cases
Feb 14, 2023
d7acdd4
Merge remote-tracking branch 'origin/feature/best_city' into feature/…
Feb 14, 2023
dc3f883
improve fake data and edit test cases
Feb 14, 2023
2778dcc
improve fake data and edit test cases
Feb 14, 2023
2527fef
fix issue with delete files from github
AmeerAmjed Feb 14, 2023
208e975
Delete FakeDataSource.kt
AmeerAmjed Feb 14, 2023
a5b9023
Delete FakeDataSource.kt
AmeerAmjed Feb 14, 2023
543fa8e
Merge branch 'feature/top_ten_countries_taxes' into develop
AmeerAmjed Feb 14, 2023
85ede82
fix merge and use fake data
AmeerAmjed Feb 14, 2023
fb40976
Merge branch 'feature/best_fashion_shopping_cities' into develop
AmeerAmjed Feb 14, 2023
b3c9301
fix merge
AmeerAmjed Feb 14, 2023
e1ab1f3
refactor code
davidsamuelx Feb 14, 2023
64702d8
add new test cases to fruit and vegetables
Feb 14, 2023
4cf27ff
Merge pull request #17 from The-Cupcake-team/feature/add_new_case_to_…
AmeerAmjed Feb 14, 2023
6fec065
refactor code
AmeerAmjed Feb 14, 2023
6bd4f4a
Merge branch 'develop' into feature/best_city_to_saving_money
AmeerAmjed Feb 14, 2023
afafb23
improve code
AmeerAmjed Feb 14, 2023
7b88adc
Merge branch 'feature/add_new_test_case_to_fruits_vegetables' into de…
AmeerAmjed Feb 14, 2023
5940012
add helper to show result app
AmeerAmjed Feb 14, 2023
13de43a
fix the logic of the feature
TarekIdrees Feb 16, 2023
1fdb013
change away get fake data
AmeerAmjed Feb 16, 2023
83cc2c1
Merge pull request #19 from The-Cupcake-team/feature/refactor_handel_…
AmeerAmjed Feb 16, 2023
52deaa0
improve the readability of the code
Feb 17, 2023
fe6b9e2
Merge remote-tracking branch 'origin/develop' into fix/logic_of_city_…
Feb 17, 2023
d51f141
generate fake data
Feb 17, 2023
5914776
write the correct test cases
Feb 17, 2023
3806c94
change style of naming testing functions
Feb 18, 2023
391c967
change style of naming testing functions
Feb 18, 2023
9cb7954
change cities names and add more data
TarekIdrees Feb 19, 2023
efaf4a8
pass input to interactor
TarekIdrees Feb 19, 2023
ba95ac5
refactor testcase
TarekIdrees Feb 19, 2023
39f98e0
pass input to execute function
TarekIdrees Feb 19, 2023
8537015
add a function for meals prices data class
TarekIdrees Feb 20, 2023
1039c4e
improve readability
TarekIdrees Feb 20, 2023
3b0489b
use invoke operator instead of execute function
TarekIdrees Feb 20, 2023
026c200
remove implicit call of invoke in helper class
TarekIdrees Feb 20, 2023
fd32b11
test: replace comparison with objects type
TarekIdrees Feb 21, 2023
9f62d4a
logic: cover the case of empty city after null check
TarekIdrees Feb 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,76 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

.idea/
.idea/shelf
/confluence/target
/dependencies/repo
/android.tests.dependencies
/dependencies/android.tests.dependencies
/dist
/local
/gh-pages
/ideaSDK
/clionSDK
/android-studio/sdk
/tmp
/intellij
workspace.xml
*.versionsBackup
/idea/testData/debugger/tinyApp/classes*
/jps-plugin/testData/kannotator
/js/js.translator/testData/out/
/js/js.translator/testData/out-min/
/js/js.translator/testData/out-pir/
.gradle/
!**/src/**/build
!**/test/**/build
!**/testData/**/*.iml
.idea/remote-targets.xml
.idea/libraries/Gradle*.xml
.idea/libraries/Maven*.xml
.idea/artifacts/PILL_*.xml
.idea/artifacts/KotlinPlugin.xml
.idea/modules
.idea/runConfigurations/JPS_*.xml
.idea/runConfigurations/PILL_*.xml
.idea/runConfigurations/_FP_*.xml
.idea/runConfigurations/_MT_*.xml
.idea/libraries
.idea/gradle.xml
.idea/inspectionProfiles/profiles_settings.xml
.idea/.name
.idea/artifacts/dist_auto_*
.idea/artifacts/dist.xml
.idea/artifacts/ideaPlugin.xml
.idea/artifacts/kotlinc.xml
.idea/artifacts/kotlin_compiler_jar.xml
.idea/artifacts/kotlin_plugin_jar.xml
.idea/artifacts/kotlin_jps_plugin_jar.xml
.idea/artifacts/kotlin_daemon_client_jar.xml
.idea/artifacts/kotlin_imports_dumper_compiler_plugin_jar.xml
.idea/artifacts/kotlin_main_kts_jar.xml
.idea/artifacts/kotlin_compiler_client_embeddable_jar.xml
.idea/artifacts/kotlin_reflect_jar.xml
.idea/artifacts/kotlin_stdlib_js_ir_*
.idea/artifacts/kotlin_test_js_ir_*
.idea/artifacts/kotlin_stdlib_wasm_*
.idea/artifacts/kotlin_test_wasm_*
.idea/artifacts/kotlinx_atomicfu_runtime_*
.idea/artifacts/kotlinx_cli_jvm_*
.idea/csv-plugin.xml
.idea/libraries-with-intellij-classes.xml
.idea/misc.xml
.idea/protoeditor.xml
node_modules/
.rpt2_cache/
libraries/tools/kotlin-test-js-runner/lib/
local.properties
buildSrcTmp/
distTmp/
outTmp/
/test.output
/kotlin-native/dist
kotlin-ide/
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

32 changes: 0 additions & 32 deletions .idea/codeStyles

This file was deleted.

16 changes: 0 additions & 16 deletions .idea/csv-plugin.xml

This file was deleted.

17 changes: 0 additions & 17 deletions .idea/gradle.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ repositories {
}

dependencies {
implementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}

tasks.test {
Expand Down
Binary file added lib/apiguardian-api-1.1.2.jar
Binary file not shown.
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.13.1.jar
Binary file not shown.
Binary file added lib/junit-jupiter-5.8.1.jar
Binary file not shown.
Binary file added lib/junit-jupiter-api-5.8.1.jar
Binary file not shown.
Binary file added lib/junit-jupiter-engine-5.8.1.jar
Binary file not shown.
Binary file added lib/junit-jupiter-params-5.8.1.jar
Binary file not shown.
Binary file added lib/junit-platform-commons-1.8.1.jar
Binary file not shown.
Binary file added lib/junit-platform-engine-1.8.1.jar
Binary file not shown.
Binary file added lib/opentest4j-1.2.0.jar
Binary file not shown.
17 changes: 3 additions & 14 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import dataSource.CsvDataSource
import dataSource.utils.CsvParser
import interactor.CostOfLivingDataSource
import interactor.GetCityHasCheapestInternetConnectionInteractor
import interactor.GetHighestSalaryAverageCititesNamesInteractor
import interactor.*
import utils.Helper

fun main() {
val csvParser = CsvParser()
val dataSource: CostOfLivingDataSource = CsvDataSource(csvParser)

val getHighestSalaryAverageCities = GetHighestSalaryAverageCititesNamesInteractor(dataSource)
println(getHighestSalaryAverageCities.execute(limit = 10))
printSeparationLine()

val getCityHasCheapestInternetConnectionInteractor = GetCityHasCheapestInternetConnectionInteractor(dataSource)
println(getCityHasCheapestInternetConnectionInteractor.execute())

}
private fun printSeparationLine(){
print("\n_______________________________\n")
Helper(dataSource).init()
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package interactor

import model.CityEntity
import model.FruitAndVegetablesPrices

class GetAverageFruitAndVegetablesInteractor(private val dataSource: CostOfLivingDataSource) {
fun execute(): List<String> {
return dataSource
.getAllCitiesData()
.filter(::excludeNullAndNonNumberSalaries)
.sortedBy(::lowestCostComparingToTheSalaries)
.take(10)
.map { it.cityName }
}

private fun excludeNullAndNonNumberSalaries(city: CityEntity): Boolean {
return city.averageMonthlyNetSalaryAfterTax != null && !city.averageMonthlyNetSalaryAfterTax.isNaN()
}

private fun FruitAndVegetablesPrices.getAverageFruitVegetablesPrice(): Double {
return mutableListOf(
tomato1kg,
potato1kg,
lettuceOneHead,
oranges1kg,
onion1kg,
banana1kg,
apples1kg
).filterNotNull().average()
}

private fun lowestCostComparingToTheSalaries(city: CityEntity): Double {
return city.fruitAndVegetablesPrices.getAverageFruitVegetablesPrice()
.div(city.averageMonthlyNetSalaryAfterTax!!)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package interactor

import model.CityEntity
import model.ClothesPrices



class GetBestCitiesToFashionShoppingInteractor(private val dataSource: CostOfLivingDataSource) {

fun execute(): List<String> {
return dataSource.getAllCitiesData()
.filter(::excludeNullClothesBrandPrices)
.sortedBy {
it.clothesPrices.findAveragePrices()
}
.take(5)
.map { it.cityName }

}

private fun excludeNullClothesBrandPrices(city: CityEntity): Boolean {
return city.clothesPrices.oneSummerDressInAChainStoreZaraHAndM != null &&
city.clothesPrices.onePairOfNikeRunningShoesMidRange != null &&
city.clothesPrices.onePairOfJeansLevis50oneOrSimilar != null
}

private fun ClothesPrices.findAveragePrices(): Float {
return listOfNotNull(
onePairOfJeansLevis50oneOrSimilar,
oneSummerDressInAChainStoreZaraHAndM,
onePairOfNikeRunningShoesMidRange,
).average().toFloat()
}
}
48 changes: 48 additions & 0 deletions src/main/kotlin/interactor/GetBestCityForSavingMoneyInteractor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package interactor

import model.CityEntity

class GetBestCityForSavingMoneyInteractor(private val dataSource: CostOfLivingDataSource) {

fun execute(isAppartmentInTheCityCentre: Boolean): CityEntity {
isAppartmentInCenter = isAppartmentInTheCityCentre
return dataSource.getAllCitiesData()
.filter(::checkNullFields)
.sortedByDescending(::calculateSavings)
.first()

}

private fun calculateSavings(city: CityEntity): Float {

val requireApartment =
if (isAppartmentInCenter) city.realEstatesPrices.apartment3BedroomsInCityCentre!!
else city.realEstatesPrices.apartment3BedroomsOutsideOfCentre!!

return (city.averageMonthlyNetSalaryAfterTax!! * 2) -
(city.foodPrices.loafOfFreshWhiteBread500g!! * 30) -
(city.foodPrices.localCheese1kg!!) -
(city.foodPrices.beefRound1kgOrEquivalentBackLegRedMeat!! * 4) -
(city.foodPrices.chickenFillets1kg!! * 10) -
(city.foodPrices.riceWhite1kg!! * 2) - 250.0f - requireApartment
}

private fun checkNullFields(city: CityEntity): Boolean {

var determineApartment = city.realEstatesPrices.apartment3BedroomsOutsideOfCentre != null
if (isAppartmentInCenter)
determineApartment = city.realEstatesPrices.apartment3BedroomsInCityCentre != null

return determineApartment &&
city.averageMonthlyNetSalaryAfterTax != null &&
city.foodPrices.loafOfFreshWhiteBread500g != null &&
city.foodPrices.localCheese1kg != null &&
city.foodPrices.beefRound1kgOrEquivalentBackLegRedMeat != null &&
city.foodPrices.chickenFillets1kg != null &&
city.foodPrices.riceWhite1kg != null
}

companion object {
private var isAppartmentInCenter = true
}
}
28 changes: 28 additions & 0 deletions src/main/kotlin/interactor/GetCitiesAverageSalary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package interactor

import model.CityEntity

class GetCitiesAverageSalary(private val dataSource: CostOfLivingDataSource) {

fun execute(country: String): List<Pair<String, Double>> {

val countryData = dataSource.getAllCitiesData().filter {
excludeNullSalariesAndLowQualityDataAndCheckCountriesName(it, country)
}

return if (countryData.isNotEmpty()) {
countryData.map {
Pair(it.cityName, it.averageMonthlyNetSalaryAfterTax!!.toDouble())
}
} else {
throw IllegalArgumentException("Invalid country name.")
}
}

private fun excludeNullSalariesAndLowQualityDataAndCheckCountriesName(city: CityEntity, country: String): Boolean {
return city.averageMonthlyNetSalaryAfterTax != null && city.dataQuality
&& city.country.equals(country, ignoreCase = true)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package interactor

import model.CityEntity

class GetCitiesNamesWithCheapestBananaPricesInteractor(private val dataSource: CostOfLivingDataSource) {
fun execute(vararg citiesNames: String): List<String> {
return dataSource.getAllCitiesData()
.filter { excludeNullBananaPriceAndIncludedCitiesNames(it, *citiesNames) }
.sortedBy { it.fruitAndVegetablesPrices.banana1kg }
.map(CityEntity::cityName)
}

private fun excludeNullBananaPriceAndIncludedCitiesNames(city: CityEntity, vararg citiesNames: String): Boolean {
return city.fruitAndVegetablesPrices.banana1kg != null
&& city.cityName.lowercase() in citiesNames.map(::toChangeFormatCityName)
}

private fun toChangeFormatCityName(string: String): String {
return string.lowercase().trim()
}

}
Loading