From 5605053fb911c753addf2421167a5f4359b85282 Mon Sep 17 00:00:00 2001 From: allankask Date: Wed, 29 Mar 2017 15:39:54 +0300 Subject: [PATCH] DiscSeeker CleanedCode --- refactoring-master/README.md | 53 +++++++++++ .../bin/rental/RentalPriceCalculator.class | Bin 0 -> 2277 bytes .../rental/RentalPriceCalculatorTest.class | Bin 0 -> 1138 bytes .../src/rental/RentalPriceCalculator.java | 82 ++++++++++++++++++ .../rental/RentalPriceCalculatorTest.java | 42 +++++++++ 5 files changed, 177 insertions(+) create mode 100644 refactoring-master/README.md create mode 100644 refactoring-master/bin/rental/RentalPriceCalculator.class create mode 100644 refactoring-master/bin/rental/RentalPriceCalculatorTest.class create mode 100644 refactoring-master/src/rental/RentalPriceCalculator.java create mode 100644 refactoring-master/test/rental/RentalPriceCalculatorTest.java diff --git a/refactoring-master/README.md b/refactoring-master/README.md new file mode 100644 index 0000000..25035bb --- /dev/null +++ b/refactoring-master/README.md @@ -0,0 +1,53 @@ +# Refactoring - autorendifirma hinnakalkulaator + +Ülesandeks on refaktoreerida programmikood selliselt, et see vastaks clean code standarditele, oleks testitud ja väikestes osades. + +# Töö käik + +Ülesande lahendamiseks toimige järgnevalt: +1. Fork'ige githubis see repositoorium enda kontole +2. kloonige `git clone URL` abil see repo enda arvutisse +3. Tehke kõik vajalikud muudatused ja commitige +4. Tehke githubis originaalrepo jaoks pull request +5. Hinde (2p) saavad tudengid, kes: + -- praktikumis kaasa töötasid + -- kelle tiim tegi pull requesti korraliku koodiga + +# Analüütiku/projektijuhi roll + +Kui tiimis on analüütik, kes ei programmeeri, siis tuleb tal hinde saamiseks koostada testiplaan, kus on kirjeldatud kõik juhtumid, mida tuleb testida. Näiteks: + +Ärinõue: autot saab rentida alates 18. eluaastast +Vajalikud testid: +1. 17-aastane ei saa autot rentida +-- sisendite kombinatsioon: vanus: 17, [...] +-- oodatav väljund: Exception +2. 18-aastane saab autot rentida +-- sisendite kombinatsioon: vanus: 18, [...] +-- oodatav väljund: hind 18-aastasele XXX EUR + +NB! Oodatavad väljundid sõltuvad ka teie programmi struktuurist. Kui originaalprogramm väljastab Exceptioni lõppkasutajale, siis teie võite vanusekontrolli viia eraldi meetodiks, mis tagastab vaid TRUE/FALSE + +Testiplaan tuleb commitida MD (readme) formaadis failina reposse. + +# Ärinõuded, millest lähtuda + + +**Taust** + +Rendiautod jagunevad klassidesse 1-5, kus 1 on kõige odavam kategooria ja 5 kõige kallim. + +**Ärireeglid autorendi ühe ööpäeva hinna arvutamiseks** + +Alla 18 aastane ei saa autot rentida +18-21-aastane saab rentida ainult klassi 1 kuuluvaid autosid + +Maksimaalne rendi hind on 1000 eurot päevas. + +Minimaalne rendi hind võrdub juhi vanusega. + +Klassides 4 ja 5 on hind 50% kallim kui juht on 25-aastane või noorem (välja arvatud madalhooajal). + +Rentida ei saa isikud, kellel on juhiluba olnud alla aasta. Kui juhiluba on olnud alla kolme aasta, siis on rendi hind 30% suurem. + +Kui isik on põhjustanud viimase aasta jooksul liiklusõnnestusi ja isik on alla 30 aasta vana, siis lisandub rendi ööpäevahinnale 15 eurot. \ No newline at end of file diff --git a/refactoring-master/bin/rental/RentalPriceCalculator.class b/refactoring-master/bin/rental/RentalPriceCalculator.class new file mode 100644 index 0000000000000000000000000000000000000000..629d6c3c8d4d878ad4fc493d0a5bea1649149c46 GIT binary patch literal 2277 zcmaJ?O>Yxd6umEYY~ncBF>y$2Ck&K=?Un>6p`=g}*Ct?UNE#DMMBO~bFZPh}j5{BQ zRO-6RE~|D?sn9)Q6QovZ_f`8Zy66w+vZ{LCn~CE>R7;+@Z|1&x&OPV)`PYAb{F#WZ z&{mvA7!@30dE8vwRJRSs&_$J-x^HsNcH$Ielzz;g@I{kboyGM>kA?0rO7#rO==r^d z=y0>r5sX-!(L~j@T#s8`i<`cP03^dGx#OGWL7se;Wpup9pAO;SY2;5vlRJjvdYgv3 zd)u-7KFZ4USw!RE z1OCVa&rHMCx!K~5A=lxjif zcZI%N->Esq6X6`R3|7T@sU;InC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DcT01wtJ&!K$YzkQd`8Zo@hb`$ zEPO+$FP@`JK$;B9P_hhJOH)5P0Lu12<)NU1E-2RpO{YeY@ maxRentalPrice) { + return maxRentalPrice; + } + + return rentalprice; + } + + + void checkIfDriverLegalAge(int ageOfDriver) { + if (ageOfDriver < minimumLegalAge) { + throw new IllegalArgumentException("Driver too young - cannot quote the price"); + } + } + + + void checkIfDriverIsSuitableForClass(int ageOfDriver, int carSizeClass) { + if (ageOfDriver <= fullLegalAge && carSizeClass > 2) { + throw new UnsupportedOperationException("Drivers 21 y/o or less can only rent Class 1 vehicles"); + } + } + + + double adaptPriceOnSeasonCarClassDriversAge(int ageOfDriver, int carSizeClass, boolean ifHighSeason, + double rentalprice) { + if (carSizeClass >= 4 && ageOfDriver <= firstRiskGroupAge && !ifHighSeason) { + rentalprice = rentalprice * 2; + } + return rentalprice; + } + + + double adaptPriceOnDriversAccidentsAndAge(int ageOfDriver, boolean hasCausedAccidentsLastYear, + double rentalprice) { + if (hasCausedAccidentsLastYear && ageOfDriver < secondRiskGroupAge) { + rentalprice += 15; + } + return rentalprice; + } + + + void checkIfLicenseUnderYear(int hadLicenseForYears) { + if (hadLicenseForYears < 1) { + throw new IllegalArgumentException("Driver must hold driving hadLicenseForYears at least for one year. Can not rent a car!"); + } + } + + + double adaptPriceOnDriversPeriod(int hadLicenseForYears, double rentalprice) { + if (hadLicenseForYears < 3) { + rentalprice = rentalprice * 1.3; + } + return rentalprice; + } +} \ No newline at end of file diff --git a/refactoring-master/test/rental/RentalPriceCalculatorTest.java b/refactoring-master/test/rental/RentalPriceCalculatorTest.java new file mode 100644 index 0000000..a837794 --- /dev/null +++ b/refactoring-master/test/rental/RentalPriceCalculatorTest.java @@ -0,0 +1,42 @@ +package rental; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class RentalPriceCalculatorTest { + private RentalPriceCalculator calculator; + @Before + public void beforeEachTest() { + // this method is called before each test + calculator = new RentalPriceCalculator(); + } + + @Test + public void priceNormalFor3YearsOfExperience() { + assertEquals(100, + calculator + .adaptPriceOnDriversPeriod(3, 100), 0.0001); + + + } + @Test + public void priceNormalFor11YearsOfExperience() { + assertEquals(100, + calculator + .adaptPriceOnDriversPeriod(11, 100), 0.0001); + + + } + @Test + public void priceHigherForUnexperiencedDriver() { + assertEquals(130, + calculator + .adaptPriceOnDriversPeriod(1, 100), 0.0001); + + + } + + +}