From 30bfe16ad9e97af37aed47aeaf0b0d7bdd89dfc7 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Wed, 20 Nov 2019 23:33:02 +0100 Subject: [PATCH 01/13] Primo tentativo --- RefactoringGolf/build.xml | 73 + RefactoringGolf/manifest.mf | 3 + RefactoringGolf/nbproject/build-impl.xml | 1770 +++++++++++++++++ RefactoringGolf/nbproject/genfiles.properties | 8 + RefactoringGolf/nbproject/project.properties | 98 + RefactoringGolf/nbproject/project.xml | 15 + .../src/paghe/buca01/BustaPaga.java | 27 + .../test/paghe/buca01/BustaPagaTest.java | 77 + 8 files changed, 2071 insertions(+) create mode 100644 RefactoringGolf/build.xml create mode 100644 RefactoringGolf/manifest.mf create mode 100644 RefactoringGolf/nbproject/build-impl.xml create mode 100644 RefactoringGolf/nbproject/genfiles.properties create mode 100644 RefactoringGolf/nbproject/project.properties create mode 100644 RefactoringGolf/nbproject/project.xml create mode 100644 RefactoringGolf/src/paghe/buca01/BustaPaga.java create mode 100644 RefactoringGolf/test/paghe/buca01/BustaPagaTest.java diff --git a/RefactoringGolf/build.xml b/RefactoringGolf/build.xml new file mode 100644 index 0000000..4a02ef0 --- /dev/null +++ b/RefactoringGolf/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project RefactoringGolf. + + + diff --git a/RefactoringGolf/manifest.mf b/RefactoringGolf/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/RefactoringGolf/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/RefactoringGolf/nbproject/build-impl.xml b/RefactoringGolf/nbproject/build-impl.xml new file mode 100644 index 0000000..b146463 --- /dev/null +++ b/RefactoringGolf/nbproject/build-impl.xml @@ -0,0 +1,1770 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RefactoringGolf/nbproject/genfiles.properties b/RefactoringGolf/nbproject/genfiles.properties new file mode 100644 index 0000000..96b69a2 --- /dev/null +++ b/RefactoringGolf/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=aed94fd7 +build.xml.script.CRC32=eaa7a348 +build.xml.stylesheet.CRC32=f85dc8f2@1.93.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=aed94fd7 +nbproject/build-impl.xml.script.CRC32=74ca37b2 +nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.93.0.48 diff --git a/RefactoringGolf/nbproject/project.properties b/RefactoringGolf/nbproject/project.properties new file mode 100644 index 0000000..152d342 --- /dev/null +++ b/RefactoringGolf/nbproject/project.properties @@ -0,0 +1,98 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/RefactoringGolf.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/RefactoringGolf +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${libs.junit_4.classpath}:\ + ${libs.hamcrest.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=11 +javac.target=11 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit_5.classpath} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=RefactoringGolf +main.class=paghe.Buca1 +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/RefactoringGolf/nbproject/project.xml b/RefactoringGolf/nbproject/project.xml new file mode 100644 index 0000000..20d0f5a --- /dev/null +++ b/RefactoringGolf/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + RefactoringGolf + + + + + + + + + diff --git a/RefactoringGolf/src/paghe/buca01/BustaPaga.java b/RefactoringGolf/src/paghe/buca01/BustaPaga.java new file mode 100644 index 0000000..a69d4ac --- /dev/null +++ b/RefactoringGolf/src/paghe/buca01/BustaPaga.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package paghe.buca01; + +/** + * + * @author Marcello Missiroli @piffy + * @author Steve Freemam @sf105 + */ + +public class BustaPaga { + private final double sal; + + public BustaPaga(final double slr) { + this.sal = slr; + } + + public double getNetto() { + final double lpst = Math.max(Math.min(sal, 20000.0) - 5000, 0.0); + final double lsst = Math.max(Math.min(sal, 40000) - 20000, 0.0); + final double ltss = Math.max(sal - 40000, 0.0); + return sal - (ltss * 0.1 + lsst * 0.2 + ltss * 0.4); + } +} diff --git a/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java b/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java new file mode 100644 index 0000000..3fbd17a --- /dev/null +++ b/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package paghe.buca01; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * + * @author marce + */ +public class BustaPagaTest { + + public BustaPagaTest() { + } + + @BeforeAll + public static void setUpClass() { + } + + @AfterAll + public static void tearDownClass() { + } + + @BeforeEach + public void setUp() { + } + + @AfterEach + public void tearDown() { + } + + /** + * Test of getNetto method, of class BustaPaga. + */ + + + @Test + public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { + BustaPaga bustaPaga = new BustaPaga(5000); + assertEquals(5000, bustaPaga.getNetto(), 1e-6); + } + + @Test + public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { + final BustaPaga bustaPaga = new BustaPaga(10000); + assertEquals(9500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(20000); + assertEquals(18500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { + final BustaPaga bustaPaga = new BustaPaga(25000); + assertEquals(22500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(40000); + assertEquals(34500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { + final BustaPaga bustaPaga = new BustaPaga(50000); + assertEquals(40500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(60000); + assertEquals(46500, bustaPaga2.getNetto(), 1e-6); + } +} From 6bf913d068b3f927eca90fbb7c259dcf73680b75 Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Thu, 21 Nov 2019 18:26:06 +0100 Subject: [PATCH 02/13] Hole01 -> Buca 01 --- .idea/.gitignore | 2 + .idea/encodings.xml | 4 + .idea/misc.xml | 7 +- .idea/uiDesigner.xml | 124 ++++++++++++++++++ README.md | 2 +- refactoring-golf.iml | 10 ++ src/bustapaga/buca01/BustaPaga.java | 16 +++ src/bustapaga/buca01/BustaPagaTest.java | 40 ++++++ src/bustapaga/buca01/istruzioni.md | 1 + .../hole02/BustaPagaTest.java} | 4 +- .../hole02/Payslip.java | 2 +- src/{payroll => bustapaga}/hole02/notes.md | 0 .../hole03/BustaPagaTest.java} | 4 +- .../hole03/Payslip.java | 2 +- src/{payroll => bustapaga}/hole03/notes.md | 0 .../hole04/BustaPagaTest.java} | 4 +- .../hole05 => bustapaga/hole04}/Payslip.java | 2 +- .../hole04/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole04/notes.md | 0 .../hole05/BustaPagaTest.java} | 4 +- .../hole06 => bustapaga/hole05}/Payslip.java | 2 +- .../hole05/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole05/notes.md | 0 .../hole06/BustaPagaTest.java} | 4 +- .../hole04 => bustapaga/hole06}/Payslip.java | 2 +- .../hole06/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole06/notes.md | 0 .../hole07/BustaPagaTest.java} | 4 +- .../hole07/Payslip.java | 2 +- .../hole07/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole07/notes.md | 0 .../hole08/BustaPagaTest.java} | 4 +- src/bustapaga/hole08/Payslip.java | 15 +++ .../hole08/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole08/notes.md | 0 .../hole09/BandedTaxCalculator.java | 2 +- .../hole09/BandedTaxCalculatorTest.java | 2 +- .../hole09/BustaPagaTaxTest.java} | 4 +- .../hole09/BustaPagaTest.java} | 4 +- src/bustapaga/hole09/Payslip.java | 15 +++ .../hole09/TaxCalculator.java | 2 +- src/{payroll => bustapaga}/hole09/notes.md | 0 .../hole10/BandedTaxCalculator.java | 2 +- .../hole10/BustaPagaTaxTest.java} | 4 +- .../hole10/BustaPagaTest.java} | 4 +- .../hole10/NullTaxCalculator.java | 2 +- src/bustapaga/hole10/Payslip.java | 15 +++ .../hole10/TaxCalculator.java | 2 +- src/payroll/hole01/Payslip.java | 16 --- src/payroll/hole01/notes.md | 1 - src/payroll/hole03/PayslipTest.java | 40 ------ src/payroll/hole08/Payslip.java | 15 --- src/payroll/hole09/Payslip.java | 15 --- src/payroll/hole10/Payslip.java | 15 --- 54 files changed, 287 insertions(+), 144 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 src/bustapaga/buca01/BustaPaga.java create mode 100644 src/bustapaga/buca01/BustaPagaTest.java create mode 100644 src/bustapaga/buca01/istruzioni.md rename src/{payroll/hole02/PayslipTest.java => bustapaga/hole02/BustaPagaTest.java} (95%) rename src/{payroll => bustapaga}/hole02/Payslip.java (95%) rename src/{payroll => bustapaga}/hole02/notes.md (100%) rename src/{payroll/hole01/PayslipTest.java => bustapaga/hole03/BustaPagaTest.java} (95%) rename src/{payroll => bustapaga}/hole03/Payslip.java (96%) rename src/{payroll => bustapaga}/hole03/notes.md (100%) rename src/{payroll/hole04/PayslipTest.java => bustapaga/hole04/BustaPagaTest.java} (96%) rename src/{payroll/hole05 => bustapaga/hole04}/Payslip.java (93%) rename src/{payroll => bustapaga}/hole04/TaxCalculator.java (94%) rename src/{payroll => bustapaga}/hole04/notes.md (100%) rename src/{payroll/hole05/PayslipTest.java => bustapaga/hole05/BustaPagaTest.java} (94%) rename src/{payroll/hole06 => bustapaga/hole05}/Payslip.java (93%) rename src/{payroll => bustapaga}/hole05/TaxCalculator.java (94%) rename src/{payroll => bustapaga}/hole05/notes.md (100%) rename src/{payroll/hole06/PayslipTest.java => bustapaga/hole06/BustaPagaTest.java} (94%) rename src/{payroll/hole04 => bustapaga/hole06}/Payslip.java (93%) rename src/{payroll => bustapaga}/hole06/TaxCalculator.java (98%) rename src/{payroll => bustapaga}/hole06/notes.md (100%) rename src/{payroll/hole07/PayslipTest.java => bustapaga/hole07/BustaPagaTest.java} (94%) rename src/{payroll => bustapaga}/hole07/Payslip.java (93%) rename src/{payroll => bustapaga}/hole07/TaxCalculator.java (98%) rename src/{payroll => bustapaga}/hole07/notes.md (100%) rename src/{payroll/hole08/PayslipTest.java => bustapaga/hole08/BustaPagaTest.java} (94%) create mode 100644 src/bustapaga/hole08/Payslip.java rename src/{payroll => bustapaga}/hole08/TaxCalculator.java (98%) rename src/{payroll => bustapaga}/hole08/notes.md (100%) rename src/{payroll => bustapaga}/hole09/BandedTaxCalculator.java (97%) rename src/{payroll => bustapaga}/hole09/BandedTaxCalculatorTest.java (97%) rename src/{payroll/hole09/PayslipTaxTest.java => bustapaga/hole09/BustaPagaTaxTest.java} (95%) rename src/{payroll/hole09/PayslipTest.java => bustapaga/hole09/BustaPagaTest.java} (81%) create mode 100644 src/bustapaga/hole09/Payslip.java rename src/{payroll => bustapaga}/hole09/TaxCalculator.java (75%) rename src/{payroll => bustapaga}/hole09/notes.md (100%) rename src/{payroll => bustapaga}/hole10/BandedTaxCalculator.java (97%) rename src/{payroll/hole10/PayslipTaxTest.java => bustapaga/hole10/BustaPagaTaxTest.java} (95%) rename src/{payroll/hole10/PayslipTest.java => bustapaga/hole10/BustaPagaTest.java} (81%) rename src/{payroll => bustapaga}/hole10/NullTaxCalculator.java (83%) create mode 100644 src/bustapaga/hole10/Payslip.java rename src/{payroll => bustapaga}/hole10/TaxCalculator.java (75%) delete mode 100644 src/payroll/hole01/Payslip.java delete mode 100644 src/payroll/hole01/notes.md delete mode 100644 src/payroll/hole03/PayslipTest.java delete mode 100644 src/payroll/hole08/Payslip.java delete mode 100644 src/payroll/hole09/Payslip.java delete mode 100644 src/payroll/hole10/Payslip.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 091444e..f8bf0f4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ - + + + - + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index f73f6ae..13529f4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ to get you to explore your IDE to see what's really possible using shortcuts and automation. The idea is to focus on one aspect of coding and see how far it can be pushed. -This repository contains multiple versions of a simple class to calculate tax on a payslip. +This repository contains multiple versions of a simple class to calculate tax on a bustaPaga. * The first 5,000 is tax free * Up to 20,000 is taxed at 10% diff --git a/refactoring-golf.iml b/refactoring-golf.iml index bb6b39c..d3fae7e 100644 --- a/refactoring-golf.iml +++ b/refactoring-golf.iml @@ -17,5 +17,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/bustapaga/buca01/BustaPaga.java b/src/bustapaga/buca01/BustaPaga.java new file mode 100644 index 0000000..f96f824 --- /dev/null +++ b/src/bustapaga/buca01/BustaPaga.java @@ -0,0 +1,16 @@ +package bustapaga.buca01; + +public class BustaPaga { + private final double stip; + + public BustaPaga(final double stpnd) { + this.stip = stpnd; + } + + public double getNetto() { + final double pst = Math.max(Math.min(stip, 20000.0) - 5000, 0.0); + final double sst = Math.max(Math.min(stip, 40000) - 20000, 0.0); + final double tst = Math.max(stip - 40000, 0.0); + return stip - (pst * 0.1 + sst * 0.2 + tst * 0.4); + } +} diff --git a/src/bustapaga/buca01/BustaPagaTest.java b/src/bustapaga/buca01/BustaPagaTest.java new file mode 100644 index 0000000..22ac77d --- /dev/null +++ b/src/bustapaga/buca01/BustaPagaTest.java @@ -0,0 +1,40 @@ +package bustapaga.buca01; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + BustaPaga bustaPaga = new BustaPaga(5000); + assertEquals(5000, bustaPaga.getNetto(), 1e-6); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + final BustaPaga bustaPaga = new BustaPaga(10000); + assertEquals(9500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(20000); + assertEquals(18500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + final BustaPaga bustaPaga = new BustaPaga(25000); + assertEquals(22500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(40000); + assertEquals(34500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + final BustaPaga bustaPaga = new BustaPaga(50000); + assertEquals(40500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(60000); + assertEquals(46500, bustaPaga2.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca01/istruzioni.md b/src/bustapaga/buca01/istruzioni.md new file mode 100644 index 0000000..94724ec --- /dev/null +++ b/src/bustapaga/buca01/istruzioni.md @@ -0,0 +1 @@ +Semplice calcolo delle tasse di uno stipendio; i nomi delle variabli devono essere leggibili diff --git a/src/payroll/hole02/PayslipTest.java b/src/bustapaga/hole02/BustaPagaTest.java similarity index 95% rename from src/payroll/hole02/PayslipTest.java rename to src/bustapaga/hole02/BustaPagaTest.java index a0217d4..bf004a4 100644 --- a/src/payroll/hole02/PayslipTest.java +++ b/src/bustapaga/hole02/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole02; +package bustapaga.hole02; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { Payslip payslip = new Payslip(5000); diff --git a/src/payroll/hole02/Payslip.java b/src/bustapaga/hole02/Payslip.java similarity index 95% rename from src/payroll/hole02/Payslip.java rename to src/bustapaga/hole02/Payslip.java index 5a0efe2..4f5a1fc 100644 --- a/src/payroll/hole02/Payslip.java +++ b/src/bustapaga/hole02/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole02; +package bustapaga.hole02; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole02/notes.md b/src/bustapaga/hole02/notes.md similarity index 100% rename from src/payroll/hole02/notes.md rename to src/bustapaga/hole02/notes.md diff --git a/src/payroll/hole01/PayslipTest.java b/src/bustapaga/hole03/BustaPagaTest.java similarity index 95% rename from src/payroll/hole01/PayslipTest.java rename to src/bustapaga/hole03/BustaPagaTest.java index cd198b3..a927686 100644 --- a/src/payroll/hole01/PayslipTest.java +++ b/src/bustapaga/hole03/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole01; +package bustapaga.hole03; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { Payslip payslip = new Payslip(5000); diff --git a/src/payroll/hole03/Payslip.java b/src/bustapaga/hole03/Payslip.java similarity index 96% rename from src/payroll/hole03/Payslip.java rename to src/bustapaga/hole03/Payslip.java index 7f9c9b3..7c14c83 100644 --- a/src/payroll/hole03/Payslip.java +++ b/src/bustapaga/hole03/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole03; +package bustapaga.hole03; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole03/notes.md b/src/bustapaga/hole03/notes.md similarity index 100% rename from src/payroll/hole03/notes.md rename to src/bustapaga/hole03/notes.md diff --git a/src/payroll/hole04/PayslipTest.java b/src/bustapaga/hole04/BustaPagaTest.java similarity index 96% rename from src/payroll/hole04/PayslipTest.java rename to src/bustapaga/hole04/BustaPagaTest.java index 010628d..fee9791 100644 --- a/src/payroll/hole04/PayslipTest.java +++ b/src/bustapaga/hole04/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole04; +package bustapaga.hole04; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { Payslip payslip = new Payslip(5000, new TaxCalculator()); diff --git a/src/payroll/hole05/Payslip.java b/src/bustapaga/hole04/Payslip.java similarity index 93% rename from src/payroll/hole05/Payslip.java rename to src/bustapaga/hole04/Payslip.java index c7a92ae..a545083 100644 --- a/src/payroll/hole05/Payslip.java +++ b/src/bustapaga/hole04/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole05; +package bustapaga.hole04; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole04/TaxCalculator.java b/src/bustapaga/hole04/TaxCalculator.java similarity index 94% rename from src/payroll/hole04/TaxCalculator.java rename to src/bustapaga/hole04/TaxCalculator.java index 6d89748..dc84155 100644 --- a/src/payroll/hole04/TaxCalculator.java +++ b/src/bustapaga/hole04/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole04; +package bustapaga.hole04; public class TaxCalculator { public double taxFor(final double grossSalary) { diff --git a/src/payroll/hole04/notes.md b/src/bustapaga/hole04/notes.md similarity index 100% rename from src/payroll/hole04/notes.md rename to src/bustapaga/hole04/notes.md diff --git a/src/payroll/hole05/PayslipTest.java b/src/bustapaga/hole05/BustaPagaTest.java similarity index 94% rename from src/payroll/hole05/PayslipTest.java rename to src/bustapaga/hole05/BustaPagaTest.java index 5d6c2c8..065ad68 100644 --- a/src/payroll/hole05/PayslipTest.java +++ b/src/bustapaga/hole05/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole05; +package bustapaga.hole05; import static org.junit.Assert.assertEquals; import org.junit.Test; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetGivenGross(5000, 5000); diff --git a/src/payroll/hole06/Payslip.java b/src/bustapaga/hole05/Payslip.java similarity index 93% rename from src/payroll/hole06/Payslip.java rename to src/bustapaga/hole05/Payslip.java index b924450..e3e2330 100644 --- a/src/payroll/hole06/Payslip.java +++ b/src/bustapaga/hole05/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole06; +package bustapaga.hole05; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole05/TaxCalculator.java b/src/bustapaga/hole05/TaxCalculator.java similarity index 94% rename from src/payroll/hole05/TaxCalculator.java rename to src/bustapaga/hole05/TaxCalculator.java index 2450abb..ce19372 100644 --- a/src/payroll/hole05/TaxCalculator.java +++ b/src/bustapaga/hole05/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole05; +package bustapaga.hole05; public class TaxCalculator { public double taxFor(final double grossSalary) { diff --git a/src/payroll/hole05/notes.md b/src/bustapaga/hole05/notes.md similarity index 100% rename from src/payroll/hole05/notes.md rename to src/bustapaga/hole05/notes.md diff --git a/src/payroll/hole06/PayslipTest.java b/src/bustapaga/hole06/BustaPagaTest.java similarity index 94% rename from src/payroll/hole06/PayslipTest.java rename to src/bustapaga/hole06/BustaPagaTest.java index 4995dc4..43f9722 100644 --- a/src/payroll/hole06/PayslipTest.java +++ b/src/bustapaga/hole06/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole06; +package bustapaga.hole06; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/payroll/hole04/Payslip.java b/src/bustapaga/hole06/Payslip.java similarity index 93% rename from src/payroll/hole04/Payslip.java rename to src/bustapaga/hole06/Payslip.java index 860a9cb..5c06420 100644 --- a/src/payroll/hole04/Payslip.java +++ b/src/bustapaga/hole06/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole04; +package bustapaga.hole06; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole06/TaxCalculator.java b/src/bustapaga/hole06/TaxCalculator.java similarity index 98% rename from src/payroll/hole06/TaxCalculator.java rename to src/bustapaga/hole06/TaxCalculator.java index 5d82476..05f9dc3 100644 --- a/src/payroll/hole06/TaxCalculator.java +++ b/src/bustapaga/hole06/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole06; +package bustapaga.hole06; public class TaxCalculator { public double taxFor(final double grossSalary) { diff --git a/src/payroll/hole06/notes.md b/src/bustapaga/hole06/notes.md similarity index 100% rename from src/payroll/hole06/notes.md rename to src/bustapaga/hole06/notes.md diff --git a/src/payroll/hole07/PayslipTest.java b/src/bustapaga/hole07/BustaPagaTest.java similarity index 94% rename from src/payroll/hole07/PayslipTest.java rename to src/bustapaga/hole07/BustaPagaTest.java index 62ef0e0..cd8edc5 100644 --- a/src/payroll/hole07/PayslipTest.java +++ b/src/bustapaga/hole07/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole07; +package bustapaga.hole07; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/payroll/hole07/Payslip.java b/src/bustapaga/hole07/Payslip.java similarity index 93% rename from src/payroll/hole07/Payslip.java rename to src/bustapaga/hole07/Payslip.java index af223d6..da0db59 100644 --- a/src/payroll/hole07/Payslip.java +++ b/src/bustapaga/hole07/Payslip.java @@ -1,4 +1,4 @@ -package payroll.hole07; +package bustapaga.hole07; public class Payslip { private final double grossSalary; diff --git a/src/payroll/hole07/TaxCalculator.java b/src/bustapaga/hole07/TaxCalculator.java similarity index 98% rename from src/payroll/hole07/TaxCalculator.java rename to src/bustapaga/hole07/TaxCalculator.java index 0fe99ac..5b9bb4c 100644 --- a/src/payroll/hole07/TaxCalculator.java +++ b/src/bustapaga/hole07/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole07; +package bustapaga.hole07; public class TaxCalculator { public double taxFor(final double grossSalary) { diff --git a/src/payroll/hole07/notes.md b/src/bustapaga/hole07/notes.md similarity index 100% rename from src/payroll/hole07/notes.md rename to src/bustapaga/hole07/notes.md diff --git a/src/payroll/hole08/PayslipTest.java b/src/bustapaga/hole08/BustaPagaTest.java similarity index 94% rename from src/payroll/hole08/PayslipTest.java rename to src/bustapaga/hole08/BustaPagaTest.java index c34bdb7..8e5b26c 100644 --- a/src/payroll/hole08/PayslipTest.java +++ b/src/bustapaga/hole08/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole08; +package bustapaga.hole08; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/bustapaga/hole08/Payslip.java b/src/bustapaga/hole08/Payslip.java new file mode 100644 index 0000000..5bf1cff --- /dev/null +++ b/src/bustapaga/hole08/Payslip.java @@ -0,0 +1,15 @@ +package bustapaga.hole08; + +public class Payslip { + private final double grossSalary; + private final TaxCalculator taxCalculator; + + public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { + this.grossSalary = grossSalary; + this.taxCalculator = taxCalculator; + } + + public double getNet() { + return grossSalary - taxCalculator.taxFor(grossSalary); + } +} diff --git a/src/payroll/hole08/TaxCalculator.java b/src/bustapaga/hole08/TaxCalculator.java similarity index 98% rename from src/payroll/hole08/TaxCalculator.java rename to src/bustapaga/hole08/TaxCalculator.java index 61e1abf..623b059 100644 --- a/src/payroll/hole08/TaxCalculator.java +++ b/src/bustapaga/hole08/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole08; +package bustapaga.hole08; public class TaxCalculator { public double taxFor(final double grossSalary) { diff --git a/src/payroll/hole08/notes.md b/src/bustapaga/hole08/notes.md similarity index 100% rename from src/payroll/hole08/notes.md rename to src/bustapaga/hole08/notes.md diff --git a/src/payroll/hole09/BandedTaxCalculator.java b/src/bustapaga/hole09/BandedTaxCalculator.java similarity index 97% rename from src/payroll/hole09/BandedTaxCalculator.java rename to src/bustapaga/hole09/BandedTaxCalculator.java index fd2eefa..8132182 100644 --- a/src/payroll/hole09/BandedTaxCalculator.java +++ b/src/bustapaga/hole09/BandedTaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole09; +package bustapaga.hole09; public class BandedTaxCalculator implements TaxCalculator { diff --git a/src/payroll/hole09/BandedTaxCalculatorTest.java b/src/bustapaga/hole09/BandedTaxCalculatorTest.java similarity index 97% rename from src/payroll/hole09/BandedTaxCalculatorTest.java rename to src/bustapaga/hole09/BandedTaxCalculatorTest.java index 1166190..bf22131 100644 --- a/src/payroll/hole09/BandedTaxCalculatorTest.java +++ b/src/bustapaga/hole09/BandedTaxCalculatorTest.java @@ -1,4 +1,4 @@ -package payroll.hole09; +package bustapaga.hole09; import org.junit.Test; diff --git a/src/payroll/hole09/PayslipTaxTest.java b/src/bustapaga/hole09/BustaPagaTaxTest.java similarity index 95% rename from src/payroll/hole09/PayslipTaxTest.java rename to src/bustapaga/hole09/BustaPagaTaxTest.java index ac4ff5e..51bd639 100644 --- a/src/payroll/hole09/PayslipTaxTest.java +++ b/src/bustapaga/hole09/BustaPagaTaxTest.java @@ -1,10 +1,10 @@ -package payroll.hole09; +package bustapaga.hole09; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTaxTest { +public class BustaPagaTaxTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/payroll/hole09/PayslipTest.java b/src/bustapaga/hole09/BustaPagaTest.java similarity index 81% rename from src/payroll/hole09/PayslipTest.java rename to src/bustapaga/hole09/BustaPagaTest.java index ca640ff..4370dc9 100644 --- a/src/payroll/hole09/PayslipTest.java +++ b/src/bustapaga/hole09/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole09; +package bustapaga.hole09; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void netIsGrossMinusTax() { final Payslip payslip = new Payslip(5000, grossSalary -> 500); diff --git a/src/bustapaga/hole09/Payslip.java b/src/bustapaga/hole09/Payslip.java new file mode 100644 index 0000000..6381ed4 --- /dev/null +++ b/src/bustapaga/hole09/Payslip.java @@ -0,0 +1,15 @@ +package bustapaga.hole09; + +public class Payslip { + private final double grossSalary; + private final TaxCalculator taxCalculator; + + public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { + this.grossSalary = grossSalary; + this.taxCalculator = taxCalculator; + } + + public double getNet() { + return grossSalary - taxCalculator.taxFor(grossSalary); + } +} diff --git a/src/payroll/hole09/TaxCalculator.java b/src/bustapaga/hole09/TaxCalculator.java similarity index 75% rename from src/payroll/hole09/TaxCalculator.java rename to src/bustapaga/hole09/TaxCalculator.java index ac37146..1e0ee13 100644 --- a/src/payroll/hole09/TaxCalculator.java +++ b/src/bustapaga/hole09/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole09; +package bustapaga.hole09; public interface TaxCalculator { double taxFor(final double grossSalary); diff --git a/src/payroll/hole09/notes.md b/src/bustapaga/hole09/notes.md similarity index 100% rename from src/payroll/hole09/notes.md rename to src/bustapaga/hole09/notes.md diff --git a/src/payroll/hole10/BandedTaxCalculator.java b/src/bustapaga/hole10/BandedTaxCalculator.java similarity index 97% rename from src/payroll/hole10/BandedTaxCalculator.java rename to src/bustapaga/hole10/BandedTaxCalculator.java index 6ae6701..0fa74ef 100644 --- a/src/payroll/hole10/BandedTaxCalculator.java +++ b/src/bustapaga/hole10/BandedTaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole10; +package bustapaga.hole10; public class BandedTaxCalculator implements TaxCalculator { private final double minimumGross; diff --git a/src/payroll/hole10/PayslipTaxTest.java b/src/bustapaga/hole10/BustaPagaTaxTest.java similarity index 95% rename from src/payroll/hole10/PayslipTaxTest.java rename to src/bustapaga/hole10/BustaPagaTaxTest.java index 2d70470..6a5c8ed 100644 --- a/src/payroll/hole10/PayslipTaxTest.java +++ b/src/bustapaga/hole10/BustaPagaTaxTest.java @@ -1,10 +1,10 @@ -package payroll.hole10; +package bustapaga.hole10; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTaxTest { +public class BustaPagaTaxTest { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/payroll/hole10/PayslipTest.java b/src/bustapaga/hole10/BustaPagaTest.java similarity index 81% rename from src/payroll/hole10/PayslipTest.java rename to src/bustapaga/hole10/BustaPagaTest.java index b42e5c4..7dabf51 100644 --- a/src/payroll/hole10/PayslipTest.java +++ b/src/bustapaga/hole10/BustaPagaTest.java @@ -1,10 +1,10 @@ -package payroll.hole10; +package bustapaga.hole10; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class PayslipTest { +public class BustaPagaTest { @Test public void netIsGrossMinusTax() { final Payslip payslip = new Payslip(5000, grossSalary -> 500); diff --git a/src/payroll/hole10/NullTaxCalculator.java b/src/bustapaga/hole10/NullTaxCalculator.java similarity index 83% rename from src/payroll/hole10/NullTaxCalculator.java rename to src/bustapaga/hole10/NullTaxCalculator.java index 96afed8..198e726 100644 --- a/src/payroll/hole10/NullTaxCalculator.java +++ b/src/bustapaga/hole10/NullTaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole10; +package bustapaga.hole10; public class NullTaxCalculator implements TaxCalculator { @Override diff --git a/src/bustapaga/hole10/Payslip.java b/src/bustapaga/hole10/Payslip.java new file mode 100644 index 0000000..ffe70f6 --- /dev/null +++ b/src/bustapaga/hole10/Payslip.java @@ -0,0 +1,15 @@ +package bustapaga.hole10; + +public class Payslip { + private final double grossSalary; + private final TaxCalculator taxCalculator; + + public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { + this.grossSalary = grossSalary; + this.taxCalculator = taxCalculator; + } + + public double getNet() { + return grossSalary - taxCalculator.taxFor(grossSalary); + } +} diff --git a/src/payroll/hole10/TaxCalculator.java b/src/bustapaga/hole10/TaxCalculator.java similarity index 75% rename from src/payroll/hole10/TaxCalculator.java rename to src/bustapaga/hole10/TaxCalculator.java index de59bfe..b2e06be 100644 --- a/src/payroll/hole10/TaxCalculator.java +++ b/src/bustapaga/hole10/TaxCalculator.java @@ -1,4 +1,4 @@ -package payroll.hole10; +package bustapaga.hole10; public interface TaxCalculator { double taxFor(final double grossSalary); diff --git a/src/payroll/hole01/Payslip.java b/src/payroll/hole01/Payslip.java deleted file mode 100644 index cd22599..0000000 --- a/src/payroll/hole01/Payslip.java +++ /dev/null @@ -1,16 +0,0 @@ -package payroll.hole01; - -public class Payslip { - private final double sal; - - public Payslip(final double slry) { - this.sal = slry; - } - - public double getNet() { - final double ltbg = Math.max(Math.min(sal, 20000.0) - 5000, 0.0); - final double mtbg = Math.max(Math.min(sal, 40000) - 20000, 0.0); - final double utbg = Math.max(sal - 40000, 0.0); - return sal - (ltbg * 0.1 + mtbg * 0.2 + utbg * 0.4); - } -} diff --git a/src/payroll/hole01/notes.md b/src/payroll/hole01/notes.md deleted file mode 100644 index d105913..0000000 --- a/src/payroll/hole01/notes.md +++ /dev/null @@ -1 +0,0 @@ -This is a simple tax calculation, but the variable names need to be readable. diff --git a/src/payroll/hole03/PayslipTest.java b/src/payroll/hole03/PayslipTest.java deleted file mode 100644 index 0f7ce3a..0000000 --- a/src/payroll/hole03/PayslipTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package payroll.hole03; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class PayslipTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - Payslip payslip = new Payslip(5000); - assertEquals(5000, payslip.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - final Payslip payslip = new Payslip(10000); - assertEquals(9500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(20000); - assertEquals(18500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - final Payslip payslip = new Payslip(25000); - assertEquals(22500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(40000); - assertEquals(34500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - final Payslip payslip = new Payslip(50000); - assertEquals(40500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(60000); - assertEquals(46500, payslip2.getNet(), 1e-6); - } -} diff --git a/src/payroll/hole08/Payslip.java b/src/payroll/hole08/Payslip.java deleted file mode 100644 index ff2993a..0000000 --- a/src/payroll/hole08/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package payroll.hole08; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/payroll/hole09/Payslip.java b/src/payroll/hole09/Payslip.java deleted file mode 100644 index 1e1cc09..0000000 --- a/src/payroll/hole09/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package payroll.hole09; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/payroll/hole10/Payslip.java b/src/payroll/hole10/Payslip.java deleted file mode 100644 index 4dfc54f..0000000 --- a/src/payroll/hole10/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package payroll.hole10; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} From 03d7907b152659bb4ef49ea44cb386d955d3ad38 Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Thu, 21 Nov 2019 22:06:08 +0100 Subject: [PATCH 03/13] Hole02 -> Buca 02 Hole03 -> Buca 03 --- src/bustapaga/buca02/BustaPaga.java | 16 ++++++++++ src/bustapaga/buca02/BustaPagaTest.java | 39 ++++++++++++++++++++++++ src/bustapaga/buca02/istruzioni.md | 3 ++ src/bustapaga/buca03/BustaPaga.java | 20 +++++++++++++ src/bustapaga/buca03/BustaPagaTest.java | 40 +++++++++++++++++++++++++ src/bustapaga/buca03/istruzioni.md | 1 + src/bustapaga/hole02/BustaPagaTest.java | 40 ------------------------- src/bustapaga/hole02/Payslip.java | 16 ---------- src/bustapaga/hole02/notes.md | 2 -- src/bustapaga/hole03/BustaPagaTest.java | 40 ------------------------- src/bustapaga/hole03/Payslip.java | 20 ------------- src/bustapaga/hole03/notes.md | 1 - 12 files changed, 119 insertions(+), 119 deletions(-) create mode 100644 src/bustapaga/buca02/BustaPaga.java create mode 100644 src/bustapaga/buca02/BustaPagaTest.java create mode 100644 src/bustapaga/buca02/istruzioni.md create mode 100644 src/bustapaga/buca03/BustaPaga.java create mode 100644 src/bustapaga/buca03/BustaPagaTest.java create mode 100644 src/bustapaga/buca03/istruzioni.md delete mode 100644 src/bustapaga/hole02/BustaPagaTest.java delete mode 100644 src/bustapaga/hole02/Payslip.java delete mode 100644 src/bustapaga/hole02/notes.md delete mode 100644 src/bustapaga/hole03/BustaPagaTest.java delete mode 100644 src/bustapaga/hole03/Payslip.java delete mode 100644 src/bustapaga/hole03/notes.md diff --git a/src/bustapaga/buca02/BustaPaga.java b/src/bustapaga/buca02/BustaPaga.java new file mode 100644 index 0000000..aef9ffa --- /dev/null +++ b/src/bustapaga/buca02/BustaPaga.java @@ -0,0 +1,16 @@ +package bustapaga.buca02; + +public class BustaPaga { + private final double imponibile; + + public BustaPaga(final double imponibile) { + this.imponibile = imponibile; + } + + public double getNetto() { + final double primoScaglione = Math.max(Math.min(imponibile, 20000.0) - 5000, 0.0); + final double secondoScaglione = Math.max(Math.min(imponibile, 40000) - 20000, 0.0); + final double terzoScaglione = Math.max(imponibile - 40000, 0.0); + return imponibile - (primoScaglione * 0.1 + secondoScaglione * 0.2 + terzoScaglione * 0.4); + } +} diff --git a/src/bustapaga/buca02/BustaPagaTest.java b/src/bustapaga/buca02/BustaPagaTest.java new file mode 100644 index 0000000..39bac53 --- /dev/null +++ b/src/bustapaga/buca02/BustaPagaTest.java @@ -0,0 +1,39 @@ +package bustapaga.buca02; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + BustaPaga bustaPaga = new BustaPaga(5000); + assertEquals(5000, bustaPaga.getNetto(), 1e-6); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + final BustaPaga bustaPaga = new BustaPaga(10000); + assertEquals(9500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(20000); + assertEquals(18500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + final BustaPaga bustaPaga = new BustaPaga(25000); + assertEquals(22500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(40000); + assertEquals(34500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + final BustaPaga bustaPaga = new BustaPaga(50000); + assertEquals(40500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(60000); + assertEquals(46500, bustaPaga2.getNetto(), 1e-6); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca02/istruzioni.md b/src/bustapaga/buca02/istruzioni.md new file mode 100644 index 0000000..7f38dd8 --- /dev/null +++ b/src/bustapaga/buca02/istruzioni.md @@ -0,0 +1,3 @@ +`Bustapaga.getNetto()` +mette assieme il calcolo delle tasse e la sottrazione dall'imponibile. +Dovrebbero essere separati diff --git a/src/bustapaga/buca03/BustaPaga.java b/src/bustapaga/buca03/BustaPaga.java new file mode 100644 index 0000000..8a737b9 --- /dev/null +++ b/src/bustapaga/buca03/BustaPaga.java @@ -0,0 +1,20 @@ +package bustapaga.buca03; + +public class BustaPaga { + private final double imponibile; + + public BustaPaga(final double imponibile) { + this.imponibile = imponibile; + } + + public double getNetto() { + return imponibile - tasseCalcolate(); + } + + public double tasseCalcolate() { + final double primoScaglione = Math.max(Math.min(imponibile, 20000.0) - 5000, 0.0); + final double secondoScaglione = Math.max(Math.min(imponibile, 40000) - 20000, 0.0); + final double terzoScaglione = Math.max(imponibile - 40000, 0.0); + return primoScaglione * 0.1 + secondoScaglione * 0.2 + terzoScaglione * 0.4; + } +} \ No newline at end of file diff --git a/src/bustapaga/buca03/BustaPagaTest.java b/src/bustapaga/buca03/BustaPagaTest.java new file mode 100644 index 0000000..f57ed44 --- /dev/null +++ b/src/bustapaga/buca03/BustaPagaTest.java @@ -0,0 +1,40 @@ +package bustapaga.buca03; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + BustaPaga bustaPaga = new BustaPaga(5000); + assertEquals(5000, bustaPaga.getNetto(), 1e-6); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + final BustaPaga bustaPaga = new BustaPaga(10000); + assertEquals(9500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(20000); + assertEquals(18500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + final BustaPaga bustaPaga = new BustaPaga(25000); + assertEquals(22500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(40000); + assertEquals(34500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + final BustaPaga bustaPaga = new BustaPaga(50000); + assertEquals(40500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(60000); + assertEquals(46500, bustaPaga2.getNetto(), 1e-6); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca03/istruzioni.md b/src/bustapaga/buca03/istruzioni.md new file mode 100644 index 0000000..3554549 --- /dev/null +++ b/src/bustapaga/buca03/istruzioni.md @@ -0,0 +1 @@ +`BustaPaga` sa troppo sul calcolo delle tasse \ No newline at end of file diff --git a/src/bustapaga/hole02/BustaPagaTest.java b/src/bustapaga/hole02/BustaPagaTest.java deleted file mode 100644 index bf004a4..0000000 --- a/src/bustapaga/hole02/BustaPagaTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package bustapaga.hole02; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - Payslip payslip = new Payslip(5000); - assertEquals(5000, payslip.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - final Payslip payslip = new Payslip(10000); - assertEquals(9500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(20000); - assertEquals(18500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - final Payslip payslip = new Payslip(25000); - assertEquals(22500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(40000); - assertEquals(34500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - final Payslip payslip = new Payslip(50000); - assertEquals(40500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(60000); - assertEquals(46500, payslip2.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole02/Payslip.java b/src/bustapaga/hole02/Payslip.java deleted file mode 100644 index 4f5a1fc..0000000 --- a/src/bustapaga/hole02/Payslip.java +++ /dev/null @@ -1,16 +0,0 @@ -package bustapaga.hole02; - -public class Payslip { - private final double grossSalary; - - public Payslip(final double grossSalary) { - this.grossSalary = grossSalary; - } - - public double getNet() { - final double lowerTaxBracketGross = Math.max(Math.min(grossSalary, 20000.0) - 5000, 0.0); - final double middleTaxBracketGross = Math.max(Math.min(grossSalary, 40000) - 20000, 0.0); - final double upperTaxBracketGross = Math.max(grossSalary - 40000, 0.0); - return grossSalary - (lowerTaxBracketGross * 0.1 + middleTaxBracketGross * 0.2 + upperTaxBracketGross * 0.4); - } -} diff --git a/src/bustapaga/hole02/notes.md b/src/bustapaga/hole02/notes.md deleted file mode 100644 index 2b215d0..0000000 --- a/src/bustapaga/hole02/notes.md +++ /dev/null @@ -1,2 +0,0 @@ -`Payslip.getNet()` mixes up both the calculation of the tax and subtraction from the gross pay. -This should be split out diff --git a/src/bustapaga/hole03/BustaPagaTest.java b/src/bustapaga/hole03/BustaPagaTest.java deleted file mode 100644 index a927686..0000000 --- a/src/bustapaga/hole03/BustaPagaTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package bustapaga.hole03; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - Payslip payslip = new Payslip(5000); - assertEquals(5000, payslip.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - final Payslip payslip = new Payslip(10000); - assertEquals(9500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(20000); - assertEquals(18500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - final Payslip payslip = new Payslip(25000); - assertEquals(22500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(40000); - assertEquals(34500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - final Payslip payslip = new Payslip(50000); - assertEquals(40500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(60000); - assertEquals(46500, payslip2.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole03/Payslip.java b/src/bustapaga/hole03/Payslip.java deleted file mode 100644 index 7c14c83..0000000 --- a/src/bustapaga/hole03/Payslip.java +++ /dev/null @@ -1,20 +0,0 @@ -package bustapaga.hole03; - -public class Payslip { - private final double grossSalary; - - public Payslip(final double grossSalary) { - this.grossSalary = grossSalary; - } - - public double getNet() { - return grossSalary - calculatedTax(); - } - - private double calculatedTax() { - final double lowerTaxBracketGross = Math.max(Math.min(grossSalary, 20000.0) - 5000, 0.0); - final double middleTaxBracketGross = Math.max(Math.min(grossSalary, 40000) - 20000, 0.0); - final double upperTaxBracketGross = Math.max(grossSalary - 40000, 0.0); - return lowerTaxBracketGross * 0.1 + middleTaxBracketGross * 0.2 + upperTaxBracketGross * 0.4; - } -} diff --git a/src/bustapaga/hole03/notes.md b/src/bustapaga/hole03/notes.md deleted file mode 100644 index 5a4dcf7..0000000 --- a/src/bustapaga/hole03/notes.md +++ /dev/null @@ -1 +0,0 @@ -`Payslip` knows too much about tax calculations From 6ac11a02b5a3b7bdb33836334c7706788369d77d Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Thu, 21 Nov 2019 23:12:15 +0100 Subject: [PATCH 04/13] Hole04 -> Buca 04 --- src/bustapaga/buca04/BustaPaga.java | 15 +++++++ src/bustapaga/buca04/BustaPagaTest.java | 40 +++++++++++++++++++ src/bustapaga/buca04/CalcolatoreTasse.java | 9 +++++ src/bustapaga/buca04/istruzioni.md | 1 + src/bustapaga/hole04/BustaPagaTest.java | 40 ------------------- src/bustapaga/hole04/Payslip.java | 15 ------- src/bustapaga/hole04/TaxCalculator.java | 10 ----- src/bustapaga/hole04/notes.md | 1 - ...t.java => BandedCalcolatoreTasseTest.java} | 2 +- 9 files changed, 66 insertions(+), 67 deletions(-) create mode 100644 src/bustapaga/buca04/BustaPaga.java create mode 100644 src/bustapaga/buca04/BustaPagaTest.java create mode 100644 src/bustapaga/buca04/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca04/istruzioni.md delete mode 100644 src/bustapaga/hole04/BustaPagaTest.java delete mode 100644 src/bustapaga/hole04/Payslip.java delete mode 100644 src/bustapaga/hole04/TaxCalculator.java delete mode 100644 src/bustapaga/hole04/notes.md rename src/bustapaga/hole09/{BandedTaxCalculatorTest.java => BandedCalcolatoreTasseTest.java} (96%) diff --git a/src/bustapaga/buca04/BustaPaga.java b/src/bustapaga/buca04/BustaPaga.java new file mode 100644 index 0000000..2d38276 --- /dev/null +++ b/src/bustapaga/buca04/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca04; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.per(imponibile); + } +} diff --git a/src/bustapaga/buca04/BustaPagaTest.java b/src/bustapaga/buca04/BustaPagaTest.java new file mode 100644 index 0000000..2bf7318 --- /dev/null +++ b/src/bustapaga/buca04/BustaPagaTest.java @@ -0,0 +1,40 @@ +package bustapaga.buca04; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + BustaPaga bustaPaga = new BustaPaga(5000, new CalcolatoreTasse()); + assertEquals(5000, bustaPaga.getNetto(), 1e-6); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + final BustaPaga bustaPaga = new BustaPaga(10000, new CalcolatoreTasse()); + assertEquals(9500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(20000, new CalcolatoreTasse()); + assertEquals(18500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + final BustaPaga bustaPaga = new BustaPaga(25000, new CalcolatoreTasse()); + assertEquals(22500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(40000, new CalcolatoreTasse()); + assertEquals(34500, bustaPaga2.getNetto(), 1e-6); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + final BustaPaga bustaPaga = new BustaPaga(50000, new CalcolatoreTasse()); + assertEquals(40500, bustaPaga.getNetto(), 1e-6); + + final BustaPaga bustaPaga2 = new BustaPaga(60000, new CalcolatoreTasse()); + assertEquals(46500, bustaPaga2.getNetto(), 1e-6); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca04/CalcolatoreTasse.java b/src/bustapaga/buca04/CalcolatoreTasse.java new file mode 100644 index 0000000..06e1a12 --- /dev/null +++ b/src/bustapaga/buca04/CalcolatoreTasse.java @@ -0,0 +1,9 @@ +package bustapaga.buca04; + +public class CalcolatoreTasse { + public double per(final double imponibile) { + final double primoScaglione = Math.max(Math.min(imponibile, 20000.0) - 5000, 0.0); + final double secondoScaglione = Math.max(Math.min(imponibile, 40000) - 20000, 0.0); + final double terzoScaglione = Math.max(imponibile - 40000, 0.0); + return primoScaglione * 0.1 + secondoScaglione * 0.2 + terzoScaglione * 0.4; } +} diff --git a/src/bustapaga/buca04/istruzioni.md b/src/bustapaga/buca04/istruzioni.md new file mode 100644 index 0000000..3a4f523 --- /dev/null +++ b/src/bustapaga/buca04/istruzioni.md @@ -0,0 +1 @@ +C'è troppa duplicazione nei test diff --git a/src/bustapaga/hole04/BustaPagaTest.java b/src/bustapaga/hole04/BustaPagaTest.java deleted file mode 100644 index fee9791..0000000 --- a/src/bustapaga/hole04/BustaPagaTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package bustapaga.hole04; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - Payslip payslip = new Payslip(5000, new TaxCalculator()); - assertEquals(5000, payslip.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - final Payslip payslip = new Payslip(10000, new TaxCalculator()); - assertEquals(9500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(20000, new TaxCalculator()); - assertEquals(18500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - final Payslip payslip = new Payslip(25000, new TaxCalculator()); - assertEquals(22500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(40000, new TaxCalculator()); - assertEquals(34500, payslip2.getNet(), 1e-6); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - final Payslip payslip = new Payslip(50000, new TaxCalculator()); - assertEquals(40500, payslip.getNet(), 1e-6); - - final Payslip payslip2 = new Payslip(60000, new TaxCalculator()); - assertEquals(46500, payslip2.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole04/Payslip.java b/src/bustapaga/hole04/Payslip.java deleted file mode 100644 index a545083..0000000 --- a/src/bustapaga/hole04/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole04; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole04/TaxCalculator.java b/src/bustapaga/hole04/TaxCalculator.java deleted file mode 100644 index dc84155..0000000 --- a/src/bustapaga/hole04/TaxCalculator.java +++ /dev/null @@ -1,10 +0,0 @@ -package bustapaga.hole04; - -public class TaxCalculator { - public double taxFor(final double grossSalary) { - final double lowerTaxBracketGross = Math.max(Math.min(grossSalary, 20000.0) - 5000, 0.0); - final double middleTaxBracketGross = Math.max(Math.min(grossSalary, 40000) - 20000, 0.0); - final double upperTaxBracketGross = Math.max(grossSalary - 40000, 0.0); - return lowerTaxBracketGross * 0.1 + middleTaxBracketGross * 0.2 + upperTaxBracketGross * 0.4; - } -} diff --git a/src/bustapaga/hole04/notes.md b/src/bustapaga/hole04/notes.md deleted file mode 100644 index de4a383..0000000 --- a/src/bustapaga/hole04/notes.md +++ /dev/null @@ -1 +0,0 @@ -There's lots of duplication in the tests diff --git a/src/bustapaga/hole09/BandedTaxCalculatorTest.java b/src/bustapaga/hole09/BandedCalcolatoreTasseTest.java similarity index 96% rename from src/bustapaga/hole09/BandedTaxCalculatorTest.java rename to src/bustapaga/hole09/BandedCalcolatoreTasseTest.java index bf22131..bc15772 100644 --- a/src/bustapaga/hole09/BandedTaxCalculatorTest.java +++ b/src/bustapaga/hole09/BandedCalcolatoreTasseTest.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BandedTaxCalculatorTest { +public class BandedCalcolatoreTasseTest { private static final double RATE_FOR_BAND = 0.1; private static final int MINIMUM_GROSS_FOR_BAND = 1000; private static final int TAX_FROM_LOWER_BAND = 1; From 186c9595e44f05a5bba436dc81785575a76cacad Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Thu, 21 Nov 2019 23:36:26 +0100 Subject: [PATCH 05/13] Hole05 -> Buca 05 --- src/bustapaga/buca05/BustaPaga.java | 15 ++++++++++ src/bustapaga/buca05/BustaPagaTest.java | 35 ++++++++++++++++++++++ src/bustapaga/buca05/CalcolatoreTasse.java | 9 ++++++ src/bustapaga/buca05/istruzioni.md | 2 ++ src/bustapaga/hole05/BustaPagaTest.java | 35 ---------------------- src/bustapaga/hole05/Payslip.java | 15 ---------- src/bustapaga/hole05/TaxCalculator.java | 10 ------- src/bustapaga/hole05/notes.md | 2 -- 8 files changed, 61 insertions(+), 62 deletions(-) create mode 100644 src/bustapaga/buca05/BustaPaga.java create mode 100644 src/bustapaga/buca05/BustaPagaTest.java create mode 100644 src/bustapaga/buca05/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca05/istruzioni.md delete mode 100644 src/bustapaga/hole05/BustaPagaTest.java delete mode 100644 src/bustapaga/hole05/Payslip.java delete mode 100644 src/bustapaga/hole05/TaxCalculator.java delete mode 100644 src/bustapaga/hole05/notes.md diff --git a/src/bustapaga/buca05/BustaPaga.java b/src/bustapaga/buca05/BustaPaga.java new file mode 100644 index 0000000..69269a4 --- /dev/null +++ b/src/bustapaga/buca05/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca05; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.per(imponibile); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca05/BustaPagaTest.java b/src/bustapaga/buca05/BustaPagaTest.java new file mode 100644 index 0000000..6ca6953 --- /dev/null +++ b/src/bustapaga/buca05/BustaPagaTest.java @@ -0,0 +1,35 @@ +package bustapaga.buca05; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + assertNettoDatoIlLordo(5000, 5000); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + assertNettoDatoIlLordo(10000, 9500); + assertNettoDatoIlLordo(20000, 18500); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + assertNettoDatoIlLordo(25000, 22500); + assertNettoDatoIlLordo(40000, 34500); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + assertNettoDatoIlLordo(50000, 40500); + assertNettoDatoIlLordo(60000, 46500); + } + + private void assertNettoDatoIlLordo(final int lordo, final int nettoAtteso) { + final BustaPaga bustaPaga = new BustaPaga(lordo, new CalcolatoreTasse()); + assertEquals(nettoAtteso, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca05/CalcolatoreTasse.java b/src/bustapaga/buca05/CalcolatoreTasse.java new file mode 100644 index 0000000..ab21c78 --- /dev/null +++ b/src/bustapaga/buca05/CalcolatoreTasse.java @@ -0,0 +1,9 @@ +package bustapaga.buca05; + +public class CalcolatoreTasse { + public double per(final double imponibile) { + final double primoScaglione = Math.max(Math.min(imponibile, 20000.0) - 5000, 0.0); + final double secondoScaglione = Math.max(Math.min(imponibile, 40000) - 20000, 0.0); + final double terzoScaglione = Math.max(imponibile - 40000, 0.0); + return primoScaglione * 0.1 + secondoScaglione * 0.2 + terzoScaglione * 0.4; } +} diff --git a/src/bustapaga/buca05/istruzioni.md b/src/bustapaga/buca05/istruzioni.md new file mode 100644 index 0000000..5830463 --- /dev/null +++ b/src/bustapaga/buca05/istruzioni.md @@ -0,0 +1,2 @@ +Il codice di 'CalcolatoreTasse' non rappresenta bene il dominio, +che ha tassi diversi a seconda dei diversi scaglioni di reddito. \ No newline at end of file diff --git a/src/bustapaga/hole05/BustaPagaTest.java b/src/bustapaga/hole05/BustaPagaTest.java deleted file mode 100644 index 065ad68..0000000 --- a/src/bustapaga/hole05/BustaPagaTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package bustapaga.hole05; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - assertNetGivenGross(5000, 5000); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - assertNetGivenGross(10000, 9500); - assertNetGivenGross(20000, 18500); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - assertNetGivenGross(25000, 22500); - assertNetGivenGross(40000, 34500); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - assertNetGivenGross(50000, 40500); - assertNetGivenGross(60000, 46500); - } - - private void assertNetGivenGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, new TaxCalculator()); - assertEquals(expectedNet, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole05/Payslip.java b/src/bustapaga/hole05/Payslip.java deleted file mode 100644 index e3e2330..0000000 --- a/src/bustapaga/hole05/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole05; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole05/TaxCalculator.java b/src/bustapaga/hole05/TaxCalculator.java deleted file mode 100644 index ce19372..0000000 --- a/src/bustapaga/hole05/TaxCalculator.java +++ /dev/null @@ -1,10 +0,0 @@ -package bustapaga.hole05; - -public class TaxCalculator { - public double taxFor(final double grossSalary) { - final double lowerTaxBracketGross = Math.max(Math.min(grossSalary, 20000.0) - 5000, 0.0); - final double middleTaxBracketGross = Math.max(Math.min(grossSalary, 40000) - 20000, 0.0); - final double upperTaxBracketGross = Math.max(grossSalary - 40000, 0.0); - return lowerTaxBracketGross * 0.1 + middleTaxBracketGross * 0.2 + upperTaxBracketGross * 0.4; - } -} diff --git a/src/bustapaga/hole05/notes.md b/src/bustapaga/hole05/notes.md deleted file mode 100644 index c77db30..0000000 --- a/src/bustapaga/hole05/notes.md +++ /dev/null @@ -1,2 +0,0 @@ -The `TaxCalculator` code does not represent the domain well, -which has different tax rates for different bands of income. From 94f5d4f95ae8e762c849260882c36bff0bee92f0 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Fri, 22 Nov 2019 16:42:26 +0100 Subject: [PATCH 06/13] spurious dir removed --- RefactoringGolf/build.xml | 73 - RefactoringGolf/manifest.mf | 3 - RefactoringGolf/nbproject/build-impl.xml | 1770 ----------------- RefactoringGolf/nbproject/genfiles.properties | 8 - RefactoringGolf/nbproject/project.properties | 98 - RefactoringGolf/nbproject/project.xml | 15 - .../src/paghe/buca01/BustaPaga.java | 27 - .../test/paghe/buca01/BustaPagaTest.java | 77 - 8 files changed, 2071 deletions(-) delete mode 100644 RefactoringGolf/build.xml delete mode 100644 RefactoringGolf/manifest.mf delete mode 100644 RefactoringGolf/nbproject/build-impl.xml delete mode 100644 RefactoringGolf/nbproject/genfiles.properties delete mode 100644 RefactoringGolf/nbproject/project.properties delete mode 100644 RefactoringGolf/nbproject/project.xml delete mode 100644 RefactoringGolf/src/paghe/buca01/BustaPaga.java delete mode 100644 RefactoringGolf/test/paghe/buca01/BustaPagaTest.java diff --git a/RefactoringGolf/build.xml b/RefactoringGolf/build.xml deleted file mode 100644 index 4a02ef0..0000000 --- a/RefactoringGolf/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project RefactoringGolf. - - - diff --git a/RefactoringGolf/manifest.mf b/RefactoringGolf/manifest.mf deleted file mode 100644 index 1574df4..0000000 --- a/RefactoringGolf/manifest.mf +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff --git a/RefactoringGolf/nbproject/build-impl.xml b/RefactoringGolf/nbproject/build-impl.xml deleted file mode 100644 index b146463..0000000 --- a/RefactoringGolf/nbproject/build-impl.xml +++ /dev/null @@ -1,1770 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RefactoringGolf/nbproject/genfiles.properties b/RefactoringGolf/nbproject/genfiles.properties deleted file mode 100644 index 96b69a2..0000000 --- a/RefactoringGolf/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=aed94fd7 -build.xml.script.CRC32=eaa7a348 -build.xml.stylesheet.CRC32=f85dc8f2@1.93.0.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=aed94fd7 -nbproject/build-impl.xml.script.CRC32=74ca37b2 -nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.93.0.48 diff --git a/RefactoringGolf/nbproject/project.properties b/RefactoringGolf/nbproject/project.properties deleted file mode 100644 index 152d342..0000000 --- a/RefactoringGolf/nbproject/project.properties +++ /dev/null @@ -1,98 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.modulepath=\ - ${run.modulepath} -debug.test.classpath=\ - ${run.test.classpath} -debug.test.modulepath=\ - ${run.test.modulepath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/RefactoringGolf.jar -dist.javadoc.dir=${dist.dir}/javadoc -dist.jlink.dir=${dist.dir}/jlink -dist.jlink.output=${dist.jlink.dir}/RefactoringGolf -excludes= -includes=** -jar.compress=false -javac.classpath=\ - ${libs.junit_4.classpath}:\ - ${libs.hamcrest.classpath} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.external.vm=true -javac.modulepath= -javac.processormodulepath= -javac.processorpath=\ - ${javac.classpath} -javac.source=11 -javac.target=11 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir}:\ - ${libs.junit_5.classpath} -javac.test.modulepath=\ - ${javac.modulepath} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.html5=false -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -# The jlink additional root modules to resolve -jlink.additionalmodules= -# The jlink additional command line parameters -jlink.additionalparam= -jlink.launcher=true -jlink.launcher.name=RefactoringGolf -main.class=paghe.Buca1 -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.modulepath=\ - ${javac.modulepath} -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -run.test.modulepath=\ - ${javac.test.modulepath} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/RefactoringGolf/nbproject/project.xml b/RefactoringGolf/nbproject/project.xml deleted file mode 100644 index 20d0f5a..0000000 --- a/RefactoringGolf/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - RefactoringGolf - - - - - - - - - diff --git a/RefactoringGolf/src/paghe/buca01/BustaPaga.java b/RefactoringGolf/src/paghe/buca01/BustaPaga.java deleted file mode 100644 index a69d4ac..0000000 --- a/RefactoringGolf/src/paghe/buca01/BustaPaga.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package paghe.buca01; - -/** - * - * @author Marcello Missiroli @piffy - * @author Steve Freemam @sf105 - */ - -public class BustaPaga { - private final double sal; - - public BustaPaga(final double slr) { - this.sal = slr; - } - - public double getNetto() { - final double lpst = Math.max(Math.min(sal, 20000.0) - 5000, 0.0); - final double lsst = Math.max(Math.min(sal, 40000) - 20000, 0.0); - final double ltss = Math.max(sal - 40000, 0.0); - return sal - (ltss * 0.1 + lsst * 0.2 + ltss * 0.4); - } -} diff --git a/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java b/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java deleted file mode 100644 index 3fbd17a..0000000 --- a/RefactoringGolf/test/paghe/buca01/BustaPagaTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package paghe.buca01; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - -/** - * - * @author marce - */ -public class BustaPagaTest { - - public BustaPagaTest() { - } - - @BeforeAll - public static void setUpClass() { - } - - @AfterAll - public static void tearDownClass() { - } - - @BeforeEach - public void setUp() { - } - - @AfterEach - public void tearDown() { - } - - /** - * Test of getNetto method, of class BustaPaga. - */ - - - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - BustaPaga bustaPaga = new BustaPaga(5000); - assertEquals(5000, bustaPaga.getNetto(), 1e-6); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - final BustaPaga bustaPaga = new BustaPaga(10000); - assertEquals(9500, bustaPaga.getNetto(), 1e-6); - - final BustaPaga bustaPaga2 = new BustaPaga(20000); - assertEquals(18500, bustaPaga2.getNetto(), 1e-6); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - final BustaPaga bustaPaga = new BustaPaga(25000); - assertEquals(22500, bustaPaga.getNetto(), 1e-6); - - final BustaPaga bustaPaga2 = new BustaPaga(40000); - assertEquals(34500, bustaPaga2.getNetto(), 1e-6); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - final BustaPaga bustaPaga = new BustaPaga(50000); - assertEquals(40500, bustaPaga.getNetto(), 1e-6); - - final BustaPaga bustaPaga2 = new BustaPaga(60000); - assertEquals(46500, bustaPaga2.getNetto(), 1e-6); - } -} From 924dbb4ee7ffe3bcf7e2eeb47d10ddd7c412bd91 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Fri, 22 Nov 2019 17:33:57 +0100 Subject: [PATCH 07/13] Hole 06 -> Buca 06 --- .idea/misc.xml | 2 +- src/bustapaga/buca06/BustaPaga.java | 15 ++++++++++ src/bustapaga/buca06/BustaPagaTest.java | 35 ++++++++++++++++++++++ src/bustapaga/buca06/CalcolatoreTasse.java | 33 ++++++++++++++++++++ src/bustapaga/buca06/istruzioni.md | 3 ++ src/bustapaga/hole06/BustaPagaTest.java | 35 ---------------------- src/bustapaga/hole06/Payslip.java | 15 ---------- src/bustapaga/hole06/TaxCalculator.java | 33 -------------------- src/bustapaga/hole06/notes.md | 4 --- 9 files changed, 87 insertions(+), 88 deletions(-) create mode 100644 src/bustapaga/buca06/BustaPaga.java create mode 100644 src/bustapaga/buca06/BustaPagaTest.java create mode 100644 src/bustapaga/buca06/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca06/istruzioni.md delete mode 100644 src/bustapaga/hole06/BustaPagaTest.java delete mode 100644 src/bustapaga/hole06/Payslip.java delete mode 100644 src/bustapaga/hole06/TaxCalculator.java delete mode 100644 src/bustapaga/hole06/notes.md diff --git a/.idea/misc.xml b/.idea/misc.xml index f8bf0f4..fe11758 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/bustapaga/buca06/BustaPaga.java b/src/bustapaga/buca06/BustaPaga.java new file mode 100644 index 0000000..674a692 --- /dev/null +++ b/src/bustapaga/buca06/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca06; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.per(imponibile); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca06/BustaPagaTest.java b/src/bustapaga/buca06/BustaPagaTest.java new file mode 100644 index 0000000..b0fe0d4 --- /dev/null +++ b/src/bustapaga/buca06/BustaPagaTest.java @@ -0,0 +1,35 @@ +package bustapaga.buca06; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + assertNettoDatoIlLordo(5000, 5000); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + assertNettoDatoIlLordo(10000, 9500); + assertNettoDatoIlLordo(20000, 18500); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + assertNettoDatoIlLordo(25000, 22500); + assertNettoDatoIlLordo(40000, 34500); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + assertNettoDatoIlLordo(50000, 40500); + assertNettoDatoIlLordo(60000, 46500); + } + + private void assertNettoDatoIlLordo(final int lordo, final int nettoAtteso) { + final BustaPaga bustaPaga = new BustaPaga(lordo, new CalcolatoreTasse()); + assertEquals(nettoAtteso, bustaPaga.getNetto(), 1e-6); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca06/CalcolatoreTasse.java b/src/bustapaga/buca06/CalcolatoreTasse.java new file mode 100644 index 0000000..44900d0 --- /dev/null +++ b/src/bustapaga/buca06/CalcolatoreTasse.java @@ -0,0 +1,33 @@ +package bustapaga.buca06; + +public class CalcolatoreTasse { + public double per(final double imponibile) { + final double inizioTerzoScaglione = 40000; + final double percentualeTerzoScaglione = 0.4; + final double tasseTerzoScaglione = tasseDelloScaglione(imponibile, inizioTerzoScaglione, percentualeTerzoScaglione); + final double imponibileResiduoPerGliScaglioniInferiori = imponibileResiduoDaTassare(imponibile, inizioTerzoScaglione); + + final double inizioSecondoScaglione = 20000; + final double percentualeSecondoScaglione = 0.2; + final double tasseSecondoScaglione = tasseDelloScaglione(imponibileResiduoPerGliScaglioniInferiori, inizioSecondoScaglione, percentualeSecondoScaglione); + final double imponibileRimanenentePerPrimoScaglione = imponibileResiduoDaTassare(imponibileResiduoPerGliScaglioniInferiori, inizioSecondoScaglione); + + final double inizioPrimoScaglione = 5000; + final double percentualePrimoScaglione = 0.1; + final double tassePrimoScaglione = tasseDelloScaglione(imponibileRimanenentePerPrimoScaglione, inizioPrimoScaglione, percentualePrimoScaglione); + + return tassePrimoScaglione + tasseSecondoScaglione + tasseTerzoScaglione; + } + + private double tasseDelloScaglione(final double imponibileEsclusoPartiGiàTassate, final double imponibileMinimoScaglione, final double percentuale) { + return imponibileDaTassareNelloScaglione(imponibileEsclusoPartiGiàTassate, imponibileMinimoScaglione) * percentuale; + } + + private double imponibileResiduoDaTassare(final double imponibile, final double imponibileMinimoScaglione) { + return Math.min(imponibile, imponibileMinimoScaglione); + } + + private double imponibileDaTassareNelloScaglione(double imponibileEsclusoPartiGiàTassate, final double imponibileMinimoScaglione) { + return Math.max(0, imponibileEsclusoPartiGiàTassate - imponibileMinimoScaglione); + } +} diff --git a/src/bustapaga/buca06/istruzioni.md b/src/bustapaga/buca06/istruzioni.md new file mode 100644 index 0000000..1d39021 --- /dev/null +++ b/src/bustapaga/buca06/istruzioni.md @@ -0,0 +1,3 @@ +`Calcolatore` ha molti dati cablati nel codice. +Sembra ci sia un pattern comune, all'inzio di ogni scaglione e il tasso di ogni scaglione, che possono cambiare. +Introdurre una struttura che rappresenti questo concetto. \ No newline at end of file diff --git a/src/bustapaga/hole06/BustaPagaTest.java b/src/bustapaga/hole06/BustaPagaTest.java deleted file mode 100644 index 43f9722..0000000 --- a/src/bustapaga/hole06/BustaPagaTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package bustapaga.hole06; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - assertNetForGross(5000, 5000); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - assertNetForGross(10000, 9500); - assertNetForGross(20000, 18500); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - assertNetForGross(25000, 22500); - assertNetForGross(40000, 34500); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - assertNetForGross(50000, 40500); - assertNetForGross(60000, 46500); - } - - private void assertNetForGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, new TaxCalculator()); - assertEquals(expectedNet, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole06/Payslip.java b/src/bustapaga/hole06/Payslip.java deleted file mode 100644 index 5c06420..0000000 --- a/src/bustapaga/hole06/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole06; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole06/TaxCalculator.java b/src/bustapaga/hole06/TaxCalculator.java deleted file mode 100644 index 05f9dc3..0000000 --- a/src/bustapaga/hole06/TaxCalculator.java +++ /dev/null @@ -1,33 +0,0 @@ -package bustapaga.hole06; - -public class TaxCalculator { - public double taxFor(final double grossSalary) { - final double upperTaxBracketStart = 40000; - final double upperTaxBracketRate = 0.4; - final double upperTaxBracketTax = taxInBand(grossSalary, upperTaxBracketStart, upperTaxBracketRate); - final double remainingGrossForMiddleAndLowerBrackets = grossToTaxInBandsBelowCurrent(grossSalary, upperTaxBracketStart); - - final double middleTaxBracketStart = 20000; - final double middleTaxBracketRate = 0.2; - final double middleTaxBracketTax = taxInBand(remainingGrossForMiddleAndLowerBrackets, middleTaxBracketStart, middleTaxBracketRate); - final double remainingGrossForLowerBracket = grossToTaxInBandsBelowCurrent(remainingGrossForMiddleAndLowerBrackets, middleTaxBracketStart); - - final double lowerTaxBracketStart = 5000; - final double lowerTaxBracketRate = 0.1; - final double lowerTaxBracketTax = taxInBand(remainingGrossForLowerBracket, lowerTaxBracketStart, lowerTaxBracketRate); - - return lowerTaxBracketTax + middleTaxBracketTax + upperTaxBracketTax; - } - - private double taxInBand(final double grossSalaryExcludingPartAlreadyTaxedAtHigherRate, final double bracketMinimumGross, final double taxRate) { - return grossToTaxInBand(grossSalaryExcludingPartAlreadyTaxedAtHigherRate, bracketMinimumGross) * taxRate; - } - - private double grossToTaxInBandsBelowCurrent(final double grossSalary, final double bracketMinimumGross) { - return Math.min(grossSalary, bracketMinimumGross); - } - - private double grossToTaxInBand(double grossSalaryExcludingPartAlreadyTaxedAtHigherRate, final double bracketMinimumGross) { - return Math.max(0, grossSalaryExcludingPartAlreadyTaxedAtHigherRate - bracketMinimumGross); - } -} diff --git a/src/bustapaga/hole06/notes.md b/src/bustapaga/hole06/notes.md deleted file mode 100644 index 905f02d..0000000 --- a/src/bustapaga/hole06/notes.md +++ /dev/null @@ -1,4 +0,0 @@ -`TaxCalculator` is very hard-coded -There appears to be a common pattern around the start of each tax bracket and -the rate for that bracket, both of which are likely to change. -Introduce a structure to represent that concept. From 8bcdc32f375557b74fce0514358e69b7c4320109 Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Fri, 22 Nov 2019 18:55:23 +0100 Subject: [PATCH 08/13] Hole 07 -> Buca 07 --- .idea/misc.xml | 2 +- src/bustapaga/buca06/istruzioni.md | 2 +- src/bustapaga/buca07/BustaPaga.java | 15 ++++++++ src/bustapaga/buca07/BustaPagaTest.java | 36 +++++++++++++++++++ src/bustapaga/buca07/CalcolatoreTasse.java | 40 ++++++++++++++++++++++ src/bustapaga/buca07/istruzioni.md | 3 ++ src/bustapaga/hole07/BustaPagaTest.java | 35 ------------------- src/bustapaga/hole07/Payslip.java | 15 -------- src/bustapaga/hole07/TaxCalculator.java | 40 ---------------------- src/bustapaga/hole07/notes.md | 4 --- 10 files changed, 96 insertions(+), 96 deletions(-) create mode 100644 src/bustapaga/buca07/BustaPaga.java create mode 100644 src/bustapaga/buca07/BustaPagaTest.java create mode 100644 src/bustapaga/buca07/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca07/istruzioni.md delete mode 100644 src/bustapaga/hole07/BustaPagaTest.java delete mode 100644 src/bustapaga/hole07/Payslip.java delete mode 100644 src/bustapaga/hole07/TaxCalculator.java delete mode 100644 src/bustapaga/hole07/notes.md diff --git a/.idea/misc.xml b/.idea/misc.xml index fe11758..7c02c94 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/bustapaga/buca06/istruzioni.md b/src/bustapaga/buca06/istruzioni.md index 1d39021..c9b63b4 100644 --- a/src/bustapaga/buca06/istruzioni.md +++ b/src/bustapaga/buca06/istruzioni.md @@ -1,3 +1,3 @@ `Calcolatore` ha molti dati cablati nel codice. -Sembra ci sia un pattern comune, all'inzio di ogni scaglione e il tasso di ogni scaglione, che possono cambiare. +Sembra ci sia un pattern comune: l'inzio di ogni scaglione e il tasso di ogni scaglione, che però possono cambiare. Introdurre una struttura che rappresenti questo concetto. \ No newline at end of file diff --git a/src/bustapaga/buca07/BustaPaga.java b/src/bustapaga/buca07/BustaPaga.java new file mode 100644 index 0000000..d186f50 --- /dev/null +++ b/src/bustapaga/buca07/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca07; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.per(imponibile); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca07/BustaPagaTest.java b/src/bustapaga/buca07/BustaPagaTest.java new file mode 100644 index 0000000..b478793 --- /dev/null +++ b/src/bustapaga/buca07/BustaPagaTest.java @@ -0,0 +1,36 @@ +package bustapaga.buca07; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + assertNettoDatoIlLordo(5000, 5000); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + assertNettoDatoIlLordo(10000, 9500); + assertNettoDatoIlLordo(20000, 18500); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + assertNettoDatoIlLordo(25000, 22500); + assertNettoDatoIlLordo(40000, 34500); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + assertNettoDatoIlLordo(50000, 40500); + assertNettoDatoIlLordo(60000, 46500); + } + + private void assertNettoDatoIlLordo(final int lordo, final int nettoAtteso) { + final BustaPaga bustaPaga = new BustaPaga(lordo, new CalcolatoreTasse()); + assertEquals(nettoAtteso, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca07/CalcolatoreTasse.java b/src/bustapaga/buca07/CalcolatoreTasse.java new file mode 100644 index 0000000..669c318 --- /dev/null +++ b/src/bustapaga/buca07/CalcolatoreTasse.java @@ -0,0 +1,40 @@ +package bustapaga.buca07; + +public class CalcolatoreTasse { + public double per(final double imponibile) { + final Scaglione terzoScaglione = new Scaglione(40000.0, 0.4); + final double tasseTerzoScaglione = terzoScaglione.tasseDelloScaglione(imponibile); + final double imponibileResiduoPerGliScaglioniInferiori = terzoScaglione.imponibileResiduoDaTassare(imponibile); + + final Scaglione secondoScaglione = new Scaglione(20000.0, 0.2); + final double tasseSecondoScaglione = secondoScaglione.tasseDelloScaglione(imponibileResiduoPerGliScaglioniInferiori); + final double imponibileResiduoPerIlPrimoScaglione = secondoScaglione.imponibileResiduoDaTassare(imponibileResiduoPerGliScaglioniInferiori); + + final Scaglione primoScaglione = new Scaglione(5000.0, 0.1); + final double tassePrimoScaglione = primoScaglione.tasseDelloScaglione(imponibileResiduoPerIlPrimoScaglione); + + return tassePrimoScaglione + tasseSecondoScaglione + tasseTerzoScaglione; + } + + private static class Scaglione { + private final double imponibileMinimo; + private final double percentuale; + + private Scaglione(double imponibileMinimo, double percentuale) { + this.imponibileMinimo = imponibileMinimo; + this.percentuale = percentuale; + } + + private double imponibileDaTassareNelloScaglione(double imponibileEsclusoPartiGiàTassate) { + return Math.max(0, imponibileEsclusoPartiGiàTassate - imponibileMinimo); + } + + private double imponibileResiduoDaTassare(final double imponibile) { + return Math.min(imponibile, imponibileMinimo); + } + + private double tasseDelloScaglione(final double imponibileEsclusoPartiGiàTassate) { + return imponibileDaTassareNelloScaglione(imponibileEsclusoPartiGiàTassate) * percentuale; + } + } +} diff --git a/src/bustapaga/buca07/istruzioni.md b/src/bustapaga/buca07/istruzioni.md new file mode 100644 index 0000000..258a24f --- /dev/null +++ b/src/bustapaga/buca07/istruzioni.md @@ -0,0 +1,3 @@ +Questa versione di `CalcolatoreTasse' è migliore, ma notate +che ci sono molte ripetizioni nel modo in cui gli scaglioni sono utilizzati. +È possibile renderli più regolare e semplificarne la struttura? diff --git a/src/bustapaga/hole07/BustaPagaTest.java b/src/bustapaga/hole07/BustaPagaTest.java deleted file mode 100644 index cd8edc5..0000000 --- a/src/bustapaga/hole07/BustaPagaTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package bustapaga.hole07; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - assertNetForGross(5000, 5000); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - assertNetForGross(10000, 9500); - assertNetForGross(20000, 18500); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - assertNetForGross(25000, 22500); - assertNetForGross(40000, 34500); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - assertNetForGross(50000, 40500); - assertNetForGross(60000, 46500); - } - - private void assertNetForGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, new TaxCalculator()); - assertEquals(expectedNet, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole07/Payslip.java b/src/bustapaga/hole07/Payslip.java deleted file mode 100644 index da0db59..0000000 --- a/src/bustapaga/hole07/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole07; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole07/TaxCalculator.java b/src/bustapaga/hole07/TaxCalculator.java deleted file mode 100644 index 5b9bb4c..0000000 --- a/src/bustapaga/hole07/TaxCalculator.java +++ /dev/null @@ -1,40 +0,0 @@ -package bustapaga.hole07; - -public class TaxCalculator { - public double taxFor(final double grossSalary) { - final TaxBand upperTaxBand = new TaxBand(40000.0, 0.4); - final double upperTaxBracketTax = upperTaxBand.taxInBand(grossSalary); - final double remainingGrossForMiddleAndLowerBrackets = upperTaxBand.grossToTaxInBandsBelowCurrent(grossSalary); - - final TaxBand middleTaxBand = new TaxBand(20000.0, 0.2); - final double middleTaxBracketTax = middleTaxBand.taxInBand(remainingGrossForMiddleAndLowerBrackets); - final double remainingGrossForLowerBracket = middleTaxBand.grossToTaxInBandsBelowCurrent(remainingGrossForMiddleAndLowerBrackets); - - final TaxBand lowerTaxBand = new TaxBand(5000.0, 0.1); - final double lowerTaxBracketTax = lowerTaxBand.taxInBand(remainingGrossForLowerBracket); - - return lowerTaxBracketTax + middleTaxBracketTax + upperTaxBracketTax; - } - - private static class TaxBand { - private final double minimumGross; - private final double taxRate; - - private TaxBand(double minimumGross, double taxRate) { - this.minimumGross = minimumGross; - this.taxRate = taxRate; - } - - private double grossToTaxInBand(double grossSalaryExcludingPartAlreadyTaxedAtHigherRate) { - return Math.max(0, grossSalaryExcludingPartAlreadyTaxedAtHigherRate - minimumGross); - } - - private double grossToTaxInBandsBelowCurrent(final double grossSalary) { - return Math.min(grossSalary, minimumGross); - } - - private double taxInBand(final double grossSalaryExcludingPartAlreadyTaxedAtHigherRate) { - return grossToTaxInBand(grossSalaryExcludingPartAlreadyTaxedAtHigherRate) * taxRate; - } - } -} diff --git a/src/bustapaga/hole07/notes.md b/src/bustapaga/hole07/notes.md deleted file mode 100644 index b0a0a1e..0000000 --- a/src/bustapaga/hole07/notes.md +++ /dev/null @@ -1,4 +0,0 @@ -This version of `TaxCalculator` is better, but notice that it's still got -repetition in the way the tax bands are used. -Can we make this more regular and simplify the structure? - From 1d6e288e29bb8cb1fc7a48cf9bf43c045240bb0c Mon Sep 17 00:00:00 2001 From: "prof@blackbird" Date: Fri, 22 Nov 2019 19:21:23 +0100 Subject: [PATCH 09/13] Hole 08 -> Buca 08 cambiato nome a metodi --- src/bustapaga/buca07/BustaPaga.java | 2 +- src/bustapaga/buca07/CalcolatoreTasse.java | 2 +- src/bustapaga/buca08/BustaPaga.java | 15 ++++++++ src/bustapaga/buca08/BustaPagaTest.java | 35 ++++++++++++++++++ src/bustapaga/buca08/CalcolatoreTasse.java | 43 ++++++++++++++++++++++ src/bustapaga/buca08/istruzioni.md | 2 + src/bustapaga/hole08/BustaPagaTest.java | 35 ------------------ src/bustapaga/hole08/Payslip.java | 15 -------- src/bustapaga/hole08/TaxCalculator.java | 43 ---------------------- src/bustapaga/hole08/notes.md | 1 - 10 files changed, 97 insertions(+), 96 deletions(-) create mode 100644 src/bustapaga/buca08/BustaPaga.java create mode 100644 src/bustapaga/buca08/BustaPagaTest.java create mode 100644 src/bustapaga/buca08/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca08/istruzioni.md delete mode 100644 src/bustapaga/hole08/BustaPagaTest.java delete mode 100644 src/bustapaga/hole08/Payslip.java delete mode 100644 src/bustapaga/hole08/TaxCalculator.java delete mode 100644 src/bustapaga/hole08/notes.md diff --git a/src/bustapaga/buca07/BustaPaga.java b/src/bustapaga/buca07/BustaPaga.java index d186f50..906e077 100644 --- a/src/bustapaga/buca07/BustaPaga.java +++ b/src/bustapaga/buca07/BustaPaga.java @@ -10,6 +10,6 @@ public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTass } public double getNetto() { - return imponibile - calcolatoreTasse.per(imponibile); + return imponibile - calcolatoreTasse.tasse(imponibile); } } \ No newline at end of file diff --git a/src/bustapaga/buca07/CalcolatoreTasse.java b/src/bustapaga/buca07/CalcolatoreTasse.java index 669c318..1a0b91c 100644 --- a/src/bustapaga/buca07/CalcolatoreTasse.java +++ b/src/bustapaga/buca07/CalcolatoreTasse.java @@ -1,7 +1,7 @@ package bustapaga.buca07; public class CalcolatoreTasse { - public double per(final double imponibile) { + public double tasse(final double imponibile) { final Scaglione terzoScaglione = new Scaglione(40000.0, 0.4); final double tasseTerzoScaglione = terzoScaglione.tasseDelloScaglione(imponibile); final double imponibileResiduoPerGliScaglioniInferiori = terzoScaglione.imponibileResiduoDaTassare(imponibile); diff --git a/src/bustapaga/buca08/BustaPaga.java b/src/bustapaga/buca08/BustaPaga.java new file mode 100644 index 0000000..46e1c73 --- /dev/null +++ b/src/bustapaga/buca08/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca08; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.tasse(imponibile); + } +} \ No newline at end of file diff --git a/src/bustapaga/buca08/BustaPagaTest.java b/src/bustapaga/buca08/BustaPagaTest.java new file mode 100644 index 0000000..8799961 --- /dev/null +++ b/src/bustapaga/buca08/BustaPagaTest.java @@ -0,0 +1,35 @@ +package bustapaga.buca08; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + assertNettoDatoIlLordo(5000, 5000); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + assertNettoDatoIlLordo(10000, 9500); + assertNettoDatoIlLordo(20000, 18500); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + assertNettoDatoIlLordo(25000, 22500); + assertNettoDatoIlLordo(40000, 34500); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + assertNettoDatoIlLordo(50000, 40500); + assertNettoDatoIlLordo(60000, 46500); + } + + private void assertNettoDatoIlLordo(final int lordo, final int nettoAtteso) { + final BustaPaga bustaPaga = new BustaPaga(lordo, new CalcolatoreTasse()); + assertEquals(nettoAtteso, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca08/CalcolatoreTasse.java b/src/bustapaga/buca08/CalcolatoreTasse.java new file mode 100644 index 0000000..270509d --- /dev/null +++ b/src/bustapaga/buca08/CalcolatoreTasse.java @@ -0,0 +1,43 @@ +package bustapaga.buca08; + +public class CalcolatoreTasse { + public double tasse(final double imponibile) { + final Scaglione primoScaglione = new Scaglione(5000.0, 0.1, null); + final Scaglione secondoScaglione = new Scaglione(20000.0, 0.2, primoScaglione); + final Scaglione terzoScaglione = new Scaglione(40000.0, 0.4, secondoScaglione); + + return terzoScaglione.tasse(imponibile); + } + + private static class Scaglione { + private final double imponibileMinimo; + private final double percentuale; + private final Scaglione scaglioneInferiore; + + private Scaglione(double imponibileMinimo, double percentuale, Scaglione scaglioneInferiore) { + this.imponibileMinimo = imponibileMinimo; + this.percentuale = percentuale; + this.scaglioneInferiore = scaglioneInferiore; + } + + private double imponibileDelloScaglione(double imponibile) { + return Math.max(0, imponibile - imponibileMinimo); + } + + private double imponibileDaTassareNegliAltriScaglioni(final double imponibile) { + return Math.min(imponibile, imponibileMinimo); + } + + private double tasseDelloScaglione(final double imponibile) { + return imponibileDelloScaglione(imponibile) * percentuale; + } + + private double tasseDegliScaglioniInferiori(double imponibile) { + return scaglioneInferiore == null ? 0 : scaglioneInferiore.tasse(imponibileDaTassareNegliAltriScaglioni(imponibile)); + } + + private double tasse(double grossSalary) { + return tasseDelloScaglione(grossSalary) + tasseDegliScaglioniInferiori(grossSalary); + } + } +} diff --git a/src/bustapaga/buca08/istruzioni.md b/src/bustapaga/buca08/istruzioni.md new file mode 100644 index 0000000..f907616 --- /dev/null +++ b/src/bustapaga/buca08/istruzioni.md @@ -0,0 +1,2 @@ +La classe `CalcolatoreTasse` sembra essere soltanto un wrapper +per Scaglione. Ne abbiamo davvero bisogno? \ No newline at end of file diff --git a/src/bustapaga/hole08/BustaPagaTest.java b/src/bustapaga/hole08/BustaPagaTest.java deleted file mode 100644 index 8e5b26c..0000000 --- a/src/bustapaga/hole08/BustaPagaTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package bustapaga.hole08; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - assertNetForGross(5000, 5000); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - assertNetForGross(10000, 9500); - assertNetForGross(20000, 18500); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - assertNetForGross(25000, 22500); - assertNetForGross(40000, 34500); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - assertNetForGross(50000, 40500); - assertNetForGross(60000, 46500); - } - - private void assertNetForGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, new TaxCalculator()); - assertEquals(expectedNet, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole08/Payslip.java b/src/bustapaga/hole08/Payslip.java deleted file mode 100644 index 5bf1cff..0000000 --- a/src/bustapaga/hole08/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole08; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole08/TaxCalculator.java b/src/bustapaga/hole08/TaxCalculator.java deleted file mode 100644 index 623b059..0000000 --- a/src/bustapaga/hole08/TaxCalculator.java +++ /dev/null @@ -1,43 +0,0 @@ -package bustapaga.hole08; - -public class TaxCalculator { - public double taxFor(final double grossSalary) { - final TaxBand lowerTaxBand = new TaxBand(5000.0, 0.1, null); - final TaxBand middleTaxBand = new TaxBand(20000.0, 0.2, lowerTaxBand); - final TaxBand upperTaxBand = new TaxBand(40000.0, 0.4, middleTaxBand); - - return upperTaxBand.taxFor(grossSalary); - } - - private static class TaxBand { - private final double minimumGross; - private final double taxRate; - private final TaxBand lowerTaxBand; - - private TaxBand(double minimumGross, double taxRate, TaxBand lowerTaxBand) { - this.minimumGross = minimumGross; - this.taxRate = taxRate; - this.lowerTaxBand = lowerTaxBand; - } - - private double grossInBand(double grossSalary) { - return Math.max(0, grossSalary - minimumGross); - } - - private double grossToTaxAtLowerBand(final double grossSalary) { - return Math.min(grossSalary, minimumGross); - } - - private double taxForBand(final double grossSalary) { - return grossInBand(grossSalary) * taxRate; - } - - private double taxForLowerBands(double grossSalary) { - return lowerTaxBand == null ? 0 : lowerTaxBand.taxFor(grossToTaxAtLowerBand(grossSalary)); - } - - private double taxFor(double grossSalary) { - return taxForBand(grossSalary) + taxForLowerBands(grossSalary); - } - } -} diff --git a/src/bustapaga/hole08/notes.md b/src/bustapaga/hole08/notes.md deleted file mode 100644 index a2e3726..0000000 --- a/src/bustapaga/hole08/notes.md +++ /dev/null @@ -1 +0,0 @@ -The `TaxCalculator` just seems to be a wrapper for the TaxBand. Do we still need it? From 9cc2814ad78a2c8ace9a3f5386764f5dfa5474a1 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Sun, 24 Nov 2019 08:58:07 +0100 Subject: [PATCH 10/13] Hole 09 -> Buca 09 --- .idea/misc.xml | 2 +- src/bustapaga/buca09/BustaPaga.java | 15 ++++++++ src/bustapaga/buca09/BustaPagaTaxTest.java | 38 +++++++++++++++++++ src/bustapaga/buca09/BustaPagaTest.java | 13 +++++++ .../buca09/CalcolatoreScaglioneTasse.java | 37 ++++++++++++++++++ .../buca09/CalcolatoreScaglioneTasseTest.java | 35 +++++++++++++++++ src/bustapaga/buca09/CalcolatoreTasse.java | 5 +++ src/bustapaga/buca09/istruzioni.md | 1 + .../hole09/BandedCalcolatoreTasseTest.java | 34 ----------------- src/bustapaga/hole09/BandedTaxCalculator.java | 35 ----------------- src/bustapaga/hole09/BustaPagaTaxTest.java | 38 ------------------- src/bustapaga/hole09/BustaPagaTest.java | 13 ------- src/bustapaga/hole09/Payslip.java | 15 -------- src/bustapaga/hole09/TaxCalculator.java | 5 --- src/bustapaga/hole09/notes.md | 2 - 15 files changed, 145 insertions(+), 143 deletions(-) create mode 100644 src/bustapaga/buca09/BustaPaga.java create mode 100644 src/bustapaga/buca09/BustaPagaTaxTest.java create mode 100644 src/bustapaga/buca09/BustaPagaTest.java create mode 100644 src/bustapaga/buca09/CalcolatoreScaglioneTasse.java create mode 100644 src/bustapaga/buca09/CalcolatoreScaglioneTasseTest.java create mode 100644 src/bustapaga/buca09/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca09/istruzioni.md delete mode 100644 src/bustapaga/hole09/BandedCalcolatoreTasseTest.java delete mode 100644 src/bustapaga/hole09/BandedTaxCalculator.java delete mode 100644 src/bustapaga/hole09/BustaPagaTaxTest.java delete mode 100644 src/bustapaga/hole09/BustaPagaTest.java delete mode 100644 src/bustapaga/hole09/Payslip.java delete mode 100644 src/bustapaga/hole09/TaxCalculator.java delete mode 100644 src/bustapaga/hole09/notes.md diff --git a/.idea/misc.xml b/.idea/misc.xml index 7c02c94..fe11758 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/src/bustapaga/buca09/BustaPaga.java b/src/bustapaga/buca09/BustaPaga.java new file mode 100644 index 0000000..33149d1 --- /dev/null +++ b/src/bustapaga/buca09/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca09; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.tasse(imponibile); + } +} diff --git a/src/bustapaga/buca09/BustaPagaTaxTest.java b/src/bustapaga/buca09/BustaPagaTaxTest.java new file mode 100644 index 0000000..ae6d1d9 --- /dev/null +++ b/src/bustapaga/buca09/BustaPagaTaxTest.java @@ -0,0 +1,38 @@ +package bustapaga.buca09; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTaxTest { + @Test + public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { + assertNettoDatoIlLordo(5000, 5000); + } + + @Test + public void tasseDelPrimoScaglioneEsclusoZonaEsentasse() { + assertNettoDatoIlLordo(10000, 9500); + assertNettoDatoIlLordo(20000, 18500); + } + + @Test + public void tasseDelSecondoScaglioneComeSommaDelleTasseDelPrimoScaglioneEDelSecondoScaglione() { + assertNettoDatoIlLordo(25000, 22500); + assertNettoDatoIlLordo(40000, 34500); + } + + @Test + public void tasseDelTerzoScaglioneComeSommaDelleTasseDiTuttiGliScaglioni() { + assertNettoDatoIlLordo(50000, 40500); + assertNettoDatoIlLordo(60000, 46500); + } + + private void assertNettoDatoIlLordo(final int lordo, final int nettoAtteso) { + final BustaPaga bustaPaga = new BustaPaga(lordo, + new CalcolatoreScaglioneTasse(40000, 0.4, + new CalcolatoreScaglioneTasse(20000, 0.2, + new CalcolatoreScaglioneTasse(5000, 0.1, null)))); + assertEquals(nettoAtteso, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca09/BustaPagaTest.java b/src/bustapaga/buca09/BustaPagaTest.java new file mode 100644 index 0000000..0e13cb0 --- /dev/null +++ b/src/bustapaga/buca09/BustaPagaTest.java @@ -0,0 +1,13 @@ +package bustapaga.buca09; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void nettoÈImponibileMenoTasse() { + final BustaPaga bustaPaga = new BustaPaga(5000, imponibile -> 500); + assertEquals(4500, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/buca09/CalcolatoreScaglioneTasse.java b/src/bustapaga/buca09/CalcolatoreScaglioneTasse.java new file mode 100644 index 0000000..62c802b --- /dev/null +++ b/src/bustapaga/buca09/CalcolatoreScaglioneTasse.java @@ -0,0 +1,37 @@ +package bustapaga.buca09; + + +public class CalcolatoreScaglioneTasse implements CalcolatoreTasse { + private final double imponibileMinimo; + private final double percentuale; + private final CalcolatoreTasse calcolatoreScaglioneInferiore; + + + + public CalcolatoreScaglioneTasse(double imponibileMinimo, double percentuale, CalcolatoreTasse calcolatoreScaglioneInferiore) { + this.imponibileMinimo = imponibileMinimo; + this.percentuale = percentuale; + this.calcolatoreScaglioneInferiore = calcolatoreScaglioneInferiore; + } + + @Override + public double tasse(double imponibile) { + return tasseDelloScaglione(imponibile) + taxForLowerBands(imponibile); + } + + private double taxForLowerBands(double imponibile) { + return calcolatoreScaglioneInferiore == null ? 0 : calcolatoreScaglioneInferiore.tasse(imponibileDaTassareNegliAltriScaglioni(imponibile)); + } + + private double imponibileDaTassareNegliAltriScaglioni(double imponibile) { + return Math.min(imponibile, imponibileMinimo); + } + + private double tasseDelloScaglione(double imponibile) { + return imponibileDelloScaglione(imponibile) * percentuale; + } + + private double imponibileDelloScaglione(double imponibile) { + return Math.max(0, imponibile - imponibileMinimo); + } +} diff --git a/src/bustapaga/buca09/CalcolatoreScaglioneTasseTest.java b/src/bustapaga/buca09/CalcolatoreScaglioneTasseTest.java new file mode 100644 index 0000000..a0d36de --- /dev/null +++ b/src/bustapaga/buca09/CalcolatoreScaglioneTasseTest.java @@ -0,0 +1,35 @@ +package bustapaga.buca09; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class CalcolatoreScaglioneTasseTest { + private static final double PERCENTUALE_SCAGLIONE = 0.1; + private static final int IMPONIBILE_MINIMO_SCAGLIONE = 1000; + private static final int TASSE_SCAGLIONE_INFERIORE = 1; + + private CalcolatoreScaglioneTasse calculator = new CalcolatoreScaglioneTasse(IMPONIBILE_MINIMO_SCAGLIONE, PERCENTUALE_SCAGLIONE, new CalcolatoreTasse() { + @Override + public double tasse(double imponibile) { + return TASSE_SCAGLIONE_INFERIORE; + } + }); + + + @Test + public void tasseDelloScaglioneInferioreÈZeroSeIlCalcolatoreInferioreÈNull() { + CalcolatoreScaglioneTasse calculator = new CalcolatoreScaglioneTasse(IMPONIBILE_MINIMO_SCAGLIONE, PERCENTUALE_SCAGLIONE, null); + assertEquals(PERCENTUALE_SCAGLIONE * (2000 - IMPONIBILE_MINIMO_SCAGLIONE), calculator.tasse(2000), 0); + } + + @Test + public void tutteLeTasseDerivanDagliScaglioniInferioriSeImponibileMinoreDelMinimoDelloScaglione() { + assertEquals(TASSE_SCAGLIONE_INFERIORE, calculator.tasse(IMPONIBILE_MINIMO_SCAGLIONE), 0); + } + + @Test + public void leTasseSonoLaSommaDelleTasseDegliScaglioniInferiorIEDiQuestoScaglione() { + assertEquals(TASSE_SCAGLIONE_INFERIORE + PERCENTUALE_SCAGLIONE * (2000 - IMPONIBILE_MINIMO_SCAGLIONE), calculator.tasse(2000), 0); + } +} diff --git a/src/bustapaga/buca09/CalcolatoreTasse.java b/src/bustapaga/buca09/CalcolatoreTasse.java new file mode 100644 index 0000000..823d201 --- /dev/null +++ b/src/bustapaga/buca09/CalcolatoreTasse.java @@ -0,0 +1,5 @@ +package bustapaga.buca09; + +public interface CalcolatoreTasse { + double tasse(final double imponibile); +} diff --git a/src/bustapaga/buca09/istruzioni.md b/src/bustapaga/buca09/istruzioni.md new file mode 100644 index 0000000..5771bba --- /dev/null +++ b/src/bustapaga/buca09/istruzioni.md @@ -0,0 +1 @@ +Il controllo sul null in `CalcolatoreScaglioneTasse` è un po' goffo. Non c'è un modo migliore? \ No newline at end of file diff --git a/src/bustapaga/hole09/BandedCalcolatoreTasseTest.java b/src/bustapaga/hole09/BandedCalcolatoreTasseTest.java deleted file mode 100644 index bc15772..0000000 --- a/src/bustapaga/hole09/BandedCalcolatoreTasseTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package bustapaga.hole09; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BandedCalcolatoreTasseTest { - private static final double RATE_FOR_BAND = 0.1; - private static final int MINIMUM_GROSS_FOR_BAND = 1000; - private static final int TAX_FROM_LOWER_BAND = 1; - - private BandedTaxCalculator calculator = new BandedTaxCalculator(MINIMUM_GROSS_FOR_BAND, RATE_FOR_BAND, new TaxCalculator() { - @Override - public double taxFor(double grossSalary) { - return TAX_FROM_LOWER_BAND; - } - }); - - @Test - public void lowerBandTaxIsZeroIfLowerBandCalculatorIsNull() { - BandedTaxCalculator calculator = new BandedTaxCalculator(MINIMUM_GROSS_FOR_BAND, RATE_FOR_BAND, null); - assertEquals(RATE_FOR_BAND * (2000 - MINIMUM_GROSS_FOR_BAND), calculator.taxFor(2000), 0); - } - - @Test - public void allTaxIsFromLowerBandsIfGrossSalaryIsLessThanMinimumForBand() { - assertEquals(TAX_FROM_LOWER_BAND, calculator.taxFor(MINIMUM_GROSS_FOR_BAND), 0); - } - - @Test - public void taxIsSumOfTaxFromLowerBandsAndTaxFromThisBand() { - assertEquals(TAX_FROM_LOWER_BAND + RATE_FOR_BAND * (2000 - MINIMUM_GROSS_FOR_BAND), calculator.taxFor(2000), 0); - } -} diff --git a/src/bustapaga/hole09/BandedTaxCalculator.java b/src/bustapaga/hole09/BandedTaxCalculator.java deleted file mode 100644 index 8132182..0000000 --- a/src/bustapaga/hole09/BandedTaxCalculator.java +++ /dev/null @@ -1,35 +0,0 @@ -package bustapaga.hole09; - - -public class BandedTaxCalculator implements TaxCalculator { - private final double minimumGross; - private final double taxRate; - private final TaxCalculator lowerBandCalculator; - - public BandedTaxCalculator(double minimumGross, double taxRate, TaxCalculator lowerBandCalculator) { - this.minimumGross = minimumGross; - this.taxRate = taxRate; - this.lowerBandCalculator = lowerBandCalculator; - } - - @Override - public double taxFor(double grossSalary) { - return taxForBand(grossSalary) + taxForLowerBands(grossSalary); - } - - private double taxForLowerBands(double grossSalary) { - return lowerBandCalculator == null ? 0 : lowerBandCalculator.taxFor(grossToTaxAtLowerBand(grossSalary)); - } - - private double grossToTaxAtLowerBand(double grossSalary) { - return Math.min(grossSalary, minimumGross); - } - - private double taxForBand(double grossSalary) { - return grossInBand(grossSalary) * taxRate; - } - - private double grossInBand(double grossSalary) { - return Math.max(0, grossSalary - minimumGross); - } -} diff --git a/src/bustapaga/hole09/BustaPagaTaxTest.java b/src/bustapaga/hole09/BustaPagaTaxTest.java deleted file mode 100644 index 51bd639..0000000 --- a/src/bustapaga/hole09/BustaPagaTaxTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package bustapaga.hole09; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTaxTest { - @Test - public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { - assertNetForGross(5000, 5000); - } - - @Test - public void taxOnAmountInLowerTaxBracketExcludesTaxFreeLimit() { - assertNetForGross(10000, 9500); - assertNetForGross(20000, 18500); - } - - @Test - public void taxOnAmountInMiddleTaxBracketIsSumOfLowerTaxBracketAmountAndAdditionalMiddleTaxBracketAmount() { - assertNetForGross(25000, 22500); - assertNetForGross(40000, 34500); - } - - @Test - public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTaxBracketAmountAndAdditionalUpperTaxBracketAmount() { - assertNetForGross(50000, 40500); - assertNetForGross(60000, 46500); - } - - private void assertNetForGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, - new BandedTaxCalculator(40000, 0.4, - new BandedTaxCalculator(20000, 0.2, - new BandedTaxCalculator(5000, 0.1, null)))); - assertEquals(expectedNet, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole09/BustaPagaTest.java b/src/bustapaga/hole09/BustaPagaTest.java deleted file mode 100644 index 4370dc9..0000000 --- a/src/bustapaga/hole09/BustaPagaTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package bustapaga.hole09; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void netIsGrossMinusTax() { - final Payslip payslip = new Payslip(5000, grossSalary -> 500); - assertEquals(4500, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole09/Payslip.java b/src/bustapaga/hole09/Payslip.java deleted file mode 100644 index 6381ed4..0000000 --- a/src/bustapaga/hole09/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole09; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole09/TaxCalculator.java b/src/bustapaga/hole09/TaxCalculator.java deleted file mode 100644 index 1e0ee13..0000000 --- a/src/bustapaga/hole09/TaxCalculator.java +++ /dev/null @@ -1,5 +0,0 @@ -package bustapaga.hole09; - -public interface TaxCalculator { - double taxFor(final double grossSalary); -} diff --git a/src/bustapaga/hole09/notes.md b/src/bustapaga/hole09/notes.md deleted file mode 100644 index b26762e..0000000 --- a/src/bustapaga/hole09/notes.md +++ /dev/null @@ -1,2 +0,0 @@ -The check for null in `BandedTaxCalculator` is a bit clumsy. Is there a better way? - From 333c1216541d0e85802bd9df5d0c3f87acb7b922 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Mon, 25 Nov 2019 19:05:00 +0100 Subject: [PATCH 11/13] Hole 10 -> Buca 10 --- README.md | 8 +- README_IT.md | 92 +++++++++++++++++++ src/bustapaga/buca10/BustaPaga.java | 15 +++ .../{hole10 => buca10}/BustaPagaTaxTest.java | 14 +-- src/bustapaga/buca10/BustaPagaTest.java | 13 +++ .../CalcolatoreScaglioneTasse.java} | 12 +-- src/bustapaga/buca10/CalcolatoreTasse.java | 5 + .../buca10/CalcolatoreTasseNullo.java | 8 ++ src/bustapaga/hole10/BustaPagaTest.java | 13 --- src/bustapaga/hole10/NullTaxCalculator.java | 8 -- src/bustapaga/hole10/Payslip.java | 15 --- src/bustapaga/hole10/TaxCalculator.java | 5 - 12 files changed, 151 insertions(+), 57 deletions(-) create mode 100644 README_IT.md create mode 100644 src/bustapaga/buca10/BustaPaga.java rename src/bustapaga/{hole10 => buca10}/BustaPagaTaxTest.java (68%) create mode 100644 src/bustapaga/buca10/BustaPagaTest.java rename src/bustapaga/{hole10/BandedTaxCalculator.java => buca10/CalcolatoreScaglioneTasse.java} (63%) create mode 100644 src/bustapaga/buca10/CalcolatoreTasse.java create mode 100644 src/bustapaga/buca10/CalcolatoreTasseNullo.java delete mode 100644 src/bustapaga/hole10/BustaPagaTest.java delete mode 100644 src/bustapaga/hole10/NullTaxCalculator.java delete mode 100644 src/bustapaga/hole10/Payslip.java delete mode 100644 src/bustapaga/hole10/TaxCalculator.java diff --git a/README.md b/README.md index 13529f4..0ec2d35 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ to get you to explore your IDE to see what's really possible using shortcuts and automation. The idea is to focus on one aspect of coding and see how far it can be pushed. -This repository contains multiple versions of a simple class to calculate tax on a bustaPaga. +This repository contains multiple versions of a simple class to calculate tax on a payslip. * The first 5,000 is tax free * Up to 20,000 is taxed at 10% @@ -64,10 +64,12 @@ These are some example scores, achieved using IntelliJ. 9 xx -## Alternative version +## Alternative versions There's an alternative version that was implemented using TDD from scratch in the `reimplemented-with-tdd` branch of the repository. +There's also an Italian version in the `italian` branch. + ## Acknowledgements This exercise was mainly taken from an example by Lance Walton. @@ -80,4 +82,4 @@ These instructions were mostly stolen from @jasongorman's - we used `double` for the calculations. Using floating point types is usually a bad idea for money, but here it's to simplify the exercises. The alternative TDD version uses `long`. Both should probably -use a decimal format. +use a decimal format. \ No newline at end of file diff --git a/README_IT.md b/README_IT.md new file mode 100644 index 0000000..d3b4d04 --- /dev/null +++ b/README_IT.md @@ -0,0 +1,92 @@ +# Refactoring Golf + +_Refactoring Golf_ è un gioco concepito per essere l'equivalemte dello stretching +per i 'muscoli' della rifattorizzazione, nonchè per spingervi a scoprire quello che +il vostro IDE può fare con scorciatoie e automatismi. L'idea è quella di concentrarsi +su un aspetto specifico del processo di codifica e capire fin dove ci si può spingere. + +Questo repo contiene svariate versioni di una classe che ha come scopo quello di calcolare +le tasse (IRPEF) di una busta paga. + +* I primi 5'000€ sono esentasse +* Lo scaglione sino a 20'000€ è tassato al 10% +* Lo scaglione sino a 40'000€ è tassato al 20% +* Oltre i 40'000€ le tesse sono al 40% + +(I valori indicati sono di fantasia - non fanno riferimento ad alcun aspetto legale ) + +Ogni versione è una rifattorizzazione delle versione precedente. Applicando la metafora del gioco +del golf, ogni versione è chiamata "buca". + +L'obiettivo è di rifattorizzare ogni _buca_ nella versione successiva nel modo più sicuro +ed efficiente, utilizzando le potenzialità dell'IDE con il minor numero di "colpi" possibili. +Un _colpo_ è definito come una azione che modifica il codice; ogni colpo costa punti. + +Il vostro compagno dovrà annotare con cura il vostro punteggio nel modo seguente: + +- 0 punti per formattazione e selezione +- 1 punto for ogni mdofica effettuata utilizzando una scorciatoia o una caratteristica dell'IDE +(esempio: refactoring automatica, template di codice, rename, Find/replace +- 2 punti per ogni modifica manuale. Notare che una singola modifica può comprendere più linee di codice. +- Nel caso che la modifica porti a un codice che fa fallire i test, la penalità è _raddoppiata_ + +Avete a disposizione 2 tentativi per ogni round per determinare il punteggio migliore. + +## Suggerimenti +- Ogni versione possiede un file chiamato `istruzioni.md` che desrive le motivazioni alla base del prossimo refactoring. +- Potrebbe essere una buona idea tenere aperto il codice su un'altra finestra, o anche sul computer del partner. +È facile perdersi quando si lavora su più file. +- Committate il codice frequentemente, specialmente dopo ogni stadio di refactoring. Ciò faciliterà un eventuale +rollback nel caso vogliate fare un secondo tentativo o vi perdiate. +- Lanciate i test dopo ogni "colpo" - per farlo basta selezionare la cartella superiore di *refactoring-golf* in +nella vista progetto e selezionare `Run 'All Tests'` dal menu pop-up. +- Controllate spesso il vostro codice in modo che sia facile tentare un refactoring più di una volta. Idea ha anche +un'ottima so it's easier to try a refactoring more than once. Idea also has +opzione _Local History_. + +## Pratica +- L'esercizio è stato scritto con _Intellj Idea_. Dovreste riuscire facilmente a clonare il repo e aprirlo + (_Open_) come progetto. +- Idea ha una _Keymap Reference_ disponibile dal menu di aiuto. Se non lo conoscete, vale la +pena leggerlo e tenerlo a portata di mano. +- Per iniziare va benissimo il Mouse, ma cercate di imparare le scorciatoie di tastiera. + +## Esempio di punteggi +Ecco qualche esempio di punteggio, ottenuto tramite IntelliJ. + + + + + + + + + + + + +
BucaPunteggio miglioreNote
1 6
2 3
3 9
4 17 molti editing manuali
5 13
6 14
7 29 Piuttosto difficile, ma fattibile
8 8
9 xx
+ +## Versione alternativa +Troverete anche una versione alternativa implementata da zero con TFF nel branch +`reimplemented-with-tdd` del repo + +La versione in inglese è presente nel branch `main`. + +## Crediti +Gran parte di questo esercizio è stato preso da Lance Walton. + +Altre idee sono prese da David Denton e Ivan Sanchez, ispirati da @ivanmoore e @rchatley + +Le istruzioni sono state per lo più rubate da @jasongorman: +Refactoring Golf. + + +## Notes + +- Usiamo`double` per i calcoli. Usare i floating point è in genere una pessima idea per il denaro, ma qui + lo abbiamo fatto per semplificare l'esercizio. La versione alternativa con TDD usa i `long`. + In entrambi i casi si dovrebbero usare i formati decimali. + +- questa traduzione è stata fatta da @piffy + diff --git a/src/bustapaga/buca10/BustaPaga.java b/src/bustapaga/buca10/BustaPaga.java new file mode 100644 index 0000000..396fe80 --- /dev/null +++ b/src/bustapaga/buca10/BustaPaga.java @@ -0,0 +1,15 @@ +package bustapaga.buca10; + +public class BustaPaga { + private final double imponibile; + private final CalcolatoreTasse calcolatoreTasse; + + public BustaPaga(final double imponibile, final CalcolatoreTasse calcolatoreTasse) { + this.imponibile = imponibile; + this.calcolatoreTasse = calcolatoreTasse; + } + + public double getNetto() { + return imponibile - calcolatoreTasse.tasse(imponibile); + } +} diff --git a/src/bustapaga/hole10/BustaPagaTaxTest.java b/src/bustapaga/buca10/BustaPagaTaxTest.java similarity index 68% rename from src/bustapaga/hole10/BustaPagaTaxTest.java rename to src/bustapaga/buca10/BustaPagaTaxTest.java index 6a5c8ed..5b4b344 100644 --- a/src/bustapaga/hole10/BustaPagaTaxTest.java +++ b/src/bustapaga/buca10/BustaPagaTaxTest.java @@ -1,4 +1,4 @@ -package bustapaga.hole10; +package bustapaga.buca10; import org.junit.Test; @@ -29,11 +29,11 @@ public void taxOnAmountInUpperTaxBracketIsSumOfLowerTaxBracketAmountAndMiddleTax } private void assertNetForGross(final int gross, final int expectedNet) { - final Payslip payslip = new Payslip(gross, - new BandedTaxCalculator(40000, 0.4, - new BandedTaxCalculator(20000, 0.2, - new BandedTaxCalculator(5000, 0.1, - new NullTaxCalculator())))); - assertEquals(expectedNet, payslip.getNet(), 1e-6); + final BustaPaga bustaPaga = new BustaPaga(gross, + new CalcolatoreScaglioneTasse(40000, 0.4, + new CalcolatoreScaglioneTasse(20000, 0.2, + new CalcolatoreScaglioneTasse(5000, 0.1, + new CalcolatoreTasseNullo())))); + assertEquals(expectedNet, bustaPaga.getNetto(), 1e-6); } } diff --git a/src/bustapaga/buca10/BustaPagaTest.java b/src/bustapaga/buca10/BustaPagaTest.java new file mode 100644 index 0000000..2ce296e --- /dev/null +++ b/src/bustapaga/buca10/BustaPagaTest.java @@ -0,0 +1,13 @@ +package bustapaga.buca10; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BustaPagaTest { + @Test + public void nettoÈImponibileMenoTasse() { + final BustaPaga bustaPaga = new BustaPaga(5000, imponibile -> 500); + assertEquals(4500, bustaPaga.getNetto(), 1e-6); + } +} diff --git a/src/bustapaga/hole10/BandedTaxCalculator.java b/src/bustapaga/buca10/CalcolatoreScaglioneTasse.java similarity index 63% rename from src/bustapaga/hole10/BandedTaxCalculator.java rename to src/bustapaga/buca10/CalcolatoreScaglioneTasse.java index 0fa74ef..e4a5c9e 100644 --- a/src/bustapaga/hole10/BandedTaxCalculator.java +++ b/src/bustapaga/buca10/CalcolatoreScaglioneTasse.java @@ -1,23 +1,23 @@ -package bustapaga.hole10; +package bustapaga.buca10; -public class BandedTaxCalculator implements TaxCalculator { +public class CalcolatoreScaglioneTasse implements CalcolatoreTasse { private final double minimumGross; private final double taxRate; - private final TaxCalculator lowerBandCalculator; + private final CalcolatoreTasse lowerBandCalculator; - public BandedTaxCalculator(double minimumGross, double taxRate, TaxCalculator lowerBandCalculator) { + public CalcolatoreScaglioneTasse(double minimumGross, double taxRate, CalcolatoreTasse lowerBandCalculator) { this.minimumGross = minimumGross; this.taxRate = taxRate; this.lowerBandCalculator = lowerBandCalculator; } @Override - public double taxFor(double grossSalary) { + public double tasse(double grossSalary) { return taxForBand(grossSalary) + getTaxForLowerBands(grossSalary); } private double getTaxForLowerBands(double grossSalary) { - return lowerBandCalculator.taxFor(grossToTaxAtLowerBand(grossSalary)); + return lowerBandCalculator.tasse(grossToTaxAtLowerBand(grossSalary)); } private double grossToTaxAtLowerBand(double grossSalary) { diff --git a/src/bustapaga/buca10/CalcolatoreTasse.java b/src/bustapaga/buca10/CalcolatoreTasse.java new file mode 100644 index 0000000..db56fad --- /dev/null +++ b/src/bustapaga/buca10/CalcolatoreTasse.java @@ -0,0 +1,5 @@ +package bustapaga.buca10; + +public interface CalcolatoreTasse { + double tasse(final double imponibile); +} diff --git a/src/bustapaga/buca10/CalcolatoreTasseNullo.java b/src/bustapaga/buca10/CalcolatoreTasseNullo.java new file mode 100644 index 0000000..d85a319 --- /dev/null +++ b/src/bustapaga/buca10/CalcolatoreTasseNullo.java @@ -0,0 +1,8 @@ +package bustapaga.buca10; + +public class CalcolatoreTasseNullo implements CalcolatoreTasse { + @Override + public double tasse(double imponibile) { + return 0; + } +} diff --git a/src/bustapaga/hole10/BustaPagaTest.java b/src/bustapaga/hole10/BustaPagaTest.java deleted file mode 100644 index 7dabf51..0000000 --- a/src/bustapaga/hole10/BustaPagaTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package bustapaga.hole10; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BustaPagaTest { - @Test - public void netIsGrossMinusTax() { - final Payslip payslip = new Payslip(5000, grossSalary -> 500); - assertEquals(4500, payslip.getNet(), 1e-6); - } -} diff --git a/src/bustapaga/hole10/NullTaxCalculator.java b/src/bustapaga/hole10/NullTaxCalculator.java deleted file mode 100644 index 198e726..0000000 --- a/src/bustapaga/hole10/NullTaxCalculator.java +++ /dev/null @@ -1,8 +0,0 @@ -package bustapaga.hole10; - -public class NullTaxCalculator implements TaxCalculator { - @Override - public double taxFor(double grossSalary) { - return 0; - } -} diff --git a/src/bustapaga/hole10/Payslip.java b/src/bustapaga/hole10/Payslip.java deleted file mode 100644 index ffe70f6..0000000 --- a/src/bustapaga/hole10/Payslip.java +++ /dev/null @@ -1,15 +0,0 @@ -package bustapaga.hole10; - -public class Payslip { - private final double grossSalary; - private final TaxCalculator taxCalculator; - - public Payslip(final double grossSalary, final TaxCalculator taxCalculator) { - this.grossSalary = grossSalary; - this.taxCalculator = taxCalculator; - } - - public double getNet() { - return grossSalary - taxCalculator.taxFor(grossSalary); - } -} diff --git a/src/bustapaga/hole10/TaxCalculator.java b/src/bustapaga/hole10/TaxCalculator.java deleted file mode 100644 index b2e06be..0000000 --- a/src/bustapaga/hole10/TaxCalculator.java +++ /dev/null @@ -1,5 +0,0 @@ -package bustapaga.hole10; - -public interface TaxCalculator { - double taxFor(final double grossSalary); -} From a6d565a4953492224a2d59ea9de04caffaf83f31 Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Sat, 30 Nov 2019 09:07:21 +0100 Subject: [PATCH 12/13] typos --- README_IT.md | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/README_IT.md b/README_IT.md index d3b4d04..f71df2b 100644 --- a/README_IT.md +++ b/README_IT.md @@ -2,54 +2,53 @@ _Refactoring Golf_ è un gioco concepito per essere l'equivalemte dello stretching per i 'muscoli' della rifattorizzazione, nonchè per spingervi a scoprire quello che -il vostro IDE può fare con scorciatoie e automatismi. L'idea è quella di concentrarsi +il vostro IDE può fare con scorciatoie e automatismi. L'idea è quella di concentrarsi su un aspetto specifico del processo di codifica e capire fin dove ci si può spingere. -Questo repo contiene svariate versioni di una classe che ha come scopo quello di calcolare -le tasse (IRPEF) di una busta paga. +Questo repo contiene svariate versioni di una classe che ha come scopo quello di calcolare +le tasse (IRPEF) di una busta paga. * I primi 5'000€ sono esentasse * Lo scaglione sino a 20'000€ è tassato al 10% * Lo scaglione sino a 40'000€ è tassato al 20% * Oltre i 40'000€ le tesse sono al 40% -(I valori indicati sono di fantasia - non fanno riferimento ad alcun aspetto legale ) +(I valori indicati sono di fantasia - non fanno riferimento ad alcun aspetto legale)- -Ogni versione è una rifattorizzazione delle versione precedente. Applicando la metafora del gioco +Ogni versione è una rifattorizzazione delle versione precedente. Applicando la metafora del gioco del golf, ogni versione è chiamata "buca". L'obiettivo è di rifattorizzare ogni _buca_ nella versione successiva nel modo più sicuro ed efficiente, utilizzando le potenzialità dell'IDE con il minor numero di "colpi" possibili. -Un _colpo_ è definito come una azione che modifica il codice; ogni colpo costa punti. +Un _colpo_ è definito come una azione che modifica il codice; ogni colpo costa punti. Il vostro compagno dovrà annotare con cura il vostro punteggio nel modo seguente: - 0 punti per formattazione e selezione -- 1 punto for ogni mdofica effettuata utilizzando una scorciatoia o una caratteristica dell'IDE -(esempio: refactoring automatica, template di codice, rename, Find/replace +- 1 punto for ogni mdofica effettuata utilizzando una scorciatoia o una caratteristica dell'IDE +(esempio: refactoring automatica, template di codice, rename, Find/replace). - 2 punti per ogni modifica manuale. Notare che una singola modifica può comprendere più linee di codice. -- Nel caso che la modifica porti a un codice che fa fallire i test, la penalità è _raddoppiata_ +- Nel caso che la modifica porti a un codice che fa fallire i test, la penalità è _raddoppiata_ Avete a disposizione 2 tentativi per ogni round per determinare il punteggio migliore. ## Suggerimenti -- Ogni versione possiede un file chiamato `istruzioni.md` che desrive le motivazioni alla base del prossimo refactoring. -- Potrebbe essere una buona idea tenere aperto il codice su un'altra finestra, o anche sul computer del partner. +- Ogni versione possiede un file chiamato `istruzioni.md` che desrive le motivazioni alla base del prossimo refactoring. +- Potrebbe essere una buona idea tenere aperto il codice su un'altra finestra, o anche sul computer del partner. È facile perdersi quando si lavora su più file. - Committate il codice frequentemente, specialmente dopo ogni stadio di refactoring. Ciò faciliterà un eventuale -rollback nel caso vogliate fare un secondo tentativo o vi perdiate. -- Lanciate i test dopo ogni "colpo" - per farlo basta selezionare la cartella superiore di *refactoring-golf* in -nella vista progetto e selezionare `Run 'All Tests'` dal menu pop-up. -- Controllate spesso il vostro codice in modo che sia facile tentare un refactoring più di una volta. Idea ha anche -un'ottima so it's easier to try a refactoring more than once. Idea also has -opzione _Local History_. +rollback nel caso vogliate fare un secondo tentativo o vi perdiate. +- Lanciate i test dopo ogni "colpo" - per farlo basta selezionare la cartella superiore di *refactoring-golf* in +nella vista progetto e selezionare `Run 'All Tests'` dal menu pop-up. +- Controllate spesso il vostro codice in modo che sia facile tentare un refactoring più di una volta. Idea ha anche +un'ottima so it's easier to try a refactoring more than once. Idea ha anche una opzione (_Local History_) che può risultare utile. ## Pratica - L'esercizio è stato scritto con _Intellj Idea_. Dovreste riuscire facilmente a clonare il repo e aprirlo - (_Open_) come progetto. -- Idea ha una _Keymap Reference_ disponibile dal menu di aiuto. Se non lo conoscete, vale la + (_Open_) come progetto. +- Idea ha una _Keymap Reference_ disponibile dal menu di aiuto. Se non lo conoscete, vale la pena leggerlo e tenerlo a portata di mano. -- Per iniziare va benissimo il Mouse, ma cercate di imparare le scorciatoie di tastiera. +- Per iniziare va benissimo usare il mouse, ma cercate di imparare le scorciatoie di tastiera. ## Esempio di punteggi Ecco qualche esempio di punteggio, ottenuto tramite IntelliJ. @@ -59,7 +58,7 @@ Ecco qualche esempio di punteggio, ottenuto tramite IntelliJ. 1 6 2 3 3 9 - 4 17 molti editing manuali + 4 17 molti editing manuali 5 13 6 14 7 29 Piuttosto difficile, ma fattibile @@ -84,9 +83,8 @@ Le istruzioni sono state per lo più rubate da @jasongorman: ## Notes -- Usiamo`double` per i calcoli. Usare i floating point è in genere una pessima idea per il denaro, ma qui - lo abbiamo fatto per semplificare l'esercizio. La versione alternativa con TDD usa i `long`. +- Usiamo`double` per i calcoli. Usare i floating point è in genere una pessima idea per memorizzare il denaro; qui + lo abbiamo fatto per semplificare l'esercizio. La versione alternativa con TDD usa i `long`. In entrambi i casi si dovrebbero usare i formati decimali. - questa traduzione è stata fatta da @piffy - From bd6051c5bf1ab7e7ef9934ea62076e797761463b Mon Sep 17 00:00:00 2001 From: Marcello Missiroli Date: Mon, 13 Apr 2020 09:24:51 +0200 Subject: [PATCH 13/13] Adattamento per repl.it (COVID-19) --- README_IT.md | 16 ++++-- src/Main.java | 8 +++ src/TestRunner.java | 56 +++++++++++++++++++ ...ustaPagaTest.java => BustaPagaTest01.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest02.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest03.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest04.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest05.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest06.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest07.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest08.java} | 2 +- ...gaTaxTest.java => BustaPagaTaxTest09.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest09.java} | 2 +- ...gaTaxTest.java => BustaPagaTaxTest10.java} | 2 +- ...ustaPagaTest.java => BustaPagaTest10.java} | 2 +- 15 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 src/Main.java create mode 100644 src/TestRunner.java rename src/bustapaga/buca01/{BustaPagaTest.java => BustaPagaTest01.java} (97%) rename src/bustapaga/buca02/{BustaPagaTest.java => BustaPagaTest02.java} (97%) rename src/bustapaga/buca03/{BustaPagaTest.java => BustaPagaTest03.java} (97%) rename src/bustapaga/buca04/{BustaPagaTest.java => BustaPagaTest04.java} (97%) rename src/bustapaga/buca05/{BustaPagaTest.java => BustaPagaTest05.java} (97%) rename src/bustapaga/buca06/{BustaPagaTest.java => BustaPagaTest06.java} (97%) rename src/bustapaga/buca07/{BustaPagaTest.java => BustaPagaTest07.java} (97%) rename src/bustapaga/buca08/{BustaPagaTest.java => BustaPagaTest08.java} (97%) rename src/bustapaga/buca09/{BustaPagaTaxTest.java => BustaPagaTaxTest09.java} (97%) rename src/bustapaga/buca09/{BustaPagaTest.java => BustaPagaTest09.java} (90%) rename src/bustapaga/buca10/{BustaPagaTaxTest.java => BustaPagaTaxTest10.java} (97%) rename src/bustapaga/buca10/{BustaPagaTest.java => BustaPagaTest10.java} (90%) diff --git a/README_IT.md b/README_IT.md index f71df2b..f360480 100644 --- a/README_IT.md +++ b/README_IT.md @@ -43,12 +43,20 @@ nella vista progetto e selezionare `Run 'All Tests'` dal menu pop-up. - Controllate spesso il vostro codice in modo che sia facile tentare un refactoring più di una volta. Idea ha anche un'ottima so it's easier to try a refactoring more than once. Idea ha anche una opzione (_Local History_) che può risultare utile. -## Pratica +## Pratica (IDE) - L'esercizio è stato scritto con _Intellj Idea_. Dovreste riuscire facilmente a clonare il repo e aprirlo (_Open_) come progetto. - Idea ha una _Keymap Reference_ disponibile dal menu di aiuto. Se non lo conoscete, vale la pena leggerlo e tenerlo a portata di mano. - Per iniziare va benissimo usare il mouse, ma cercate di imparare le scorciatoie di tastiera. +- Non dovrebbero esserci problemi di sorta usando altri IDE (Eclipse, VS, VSC, Netbeans), ma l'importazione va fatta +manualmente e potrebbero essere necessari aggiustamenti + +#Pratica (Repl) +- L'esercizio è stato adattato per essere usato online tramite Repl.it. Importate questo repo in Repl.it e tutto +dovrebbe funzionare. +- Lanciando il main si lanciano i test della buca 1. Per cambiare buca basta modificare il parametro +passato a TestRunnen, nel medoto Main. ## Esempio di punteggi Ecco qualche esempio di punteggio, ottenuto tramite IntelliJ. @@ -66,12 +74,12 @@ Ecco qualche esempio di punteggio, ottenuto tramite IntelliJ. 9 xx -## Versione alternativa +## Versioni alternative +La versione in inglese è presente nel branch `main`. + Troverete anche una versione alternativa implementata da zero con TFF nel branch `reimplemented-with-tdd` del repo -La versione in inglese è presente nel branch `main`. - ## Crediti Gran parte di questo esercizio è stato preso da Lance Walton. diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..b597197 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,8 @@ +public class Main { + + + public static void main(String[] args) { + TestRunner tr = new TestRunner(); + tr.main(1); + } +} \ No newline at end of file diff --git a/src/TestRunner.java b/src/TestRunner.java new file mode 100644 index 0000000..2e2bb8c --- /dev/null +++ b/src/TestRunner.java @@ -0,0 +1,56 @@ +import bustapaga.buca01.BustaPagaTest01; +import bustapaga.buca02.BustaPagaTest02; +import bustapaga.buca03.BustaPagaTest03; +import bustapaga.buca04.BustaPagaTest04; +import bustapaga.buca05.BustaPagaTest05; +import bustapaga.buca06.BustaPagaTest06; +import bustapaga.buca07.BustaPagaTest07; +import bustapaga.buca08.BustaPagaTest08; +import bustapaga.buca09.BustaPagaTaxTest09; +import bustapaga.buca09.BustaPagaTest09; +import bustapaga.buca09.CalcolatoreScaglioneTasseTest; +import bustapaga.buca10.BustaPagaTaxTest10; +import bustapaga.buca10.BustaPagaTest10; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; + +public class TestRunner { + public static void main(int buca) { + int count=0,count2=0,count3=0; + Result result=null, result2=null,result3=null; + switch (buca) { + case 1 : result = JUnitCore.runClasses(BustaPagaTest01.class); break; + case 2 : result = JUnitCore.runClasses(BustaPagaTest02.class); break; + case 3 : result = JUnitCore.runClasses(BustaPagaTest03.class); break; + case 4 : result = JUnitCore.runClasses(BustaPagaTest04.class); break; + case 5 : result = JUnitCore.runClasses(BustaPagaTest05.class); break; + case 6 : result = JUnitCore.runClasses(BustaPagaTest06.class); break; + case 7 : result = JUnitCore.runClasses(BustaPagaTest07.class); break; + case 8 : result = JUnitCore.runClasses(BustaPagaTest08.class); break; + case 9 : result = JUnitCore.runClasses(BustaPagaTest09.class); + result2 = JUnitCore.runClasses(BustaPagaTaxTest09.class); + result3 = JUnitCore.runClasses(CalcolatoreScaglioneTasseTest.class);break; + case 10 : result = JUnitCore.runClasses(BustaPagaTest10.class); + result2 = JUnitCore.runClasses(BustaPagaTaxTest10.class);break; + } + for (Failure failure : result.getFailures()) { + System.out.println(failure.toString()); + count++; + } + + + System.out.println("\nBustaPagaTest"+buca+":"); + System.out.println(result.wasSuccessful() ? "OK" : "Test con errori: "+count); + + if (buca==9 || buca==10) { + for (Failure failure : result2.getFailures()) { + System.out.println(failure.toString()); + count2++; + } + System.out.println("\nBustaPagaTaxTest"+buca+":"); + System.out.println(result2.wasSuccessful() ? "OK" : "Test con errori: "+count2); + } + + } +} diff --git a/src/bustapaga/buca01/BustaPagaTest.java b/src/bustapaga/buca01/BustaPagaTest01.java similarity index 97% rename from src/bustapaga/buca01/BustaPagaTest.java rename to src/bustapaga/buca01/BustaPagaTest01.java index 22ac77d..5833c86 100644 --- a/src/bustapaga/buca01/BustaPagaTest.java +++ b/src/bustapaga/buca01/BustaPagaTest01.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest01 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { BustaPaga bustaPaga = new BustaPaga(5000); diff --git a/src/bustapaga/buca02/BustaPagaTest.java b/src/bustapaga/buca02/BustaPagaTest02.java similarity index 97% rename from src/bustapaga/buca02/BustaPagaTest.java rename to src/bustapaga/buca02/BustaPagaTest02.java index 39bac53..a9c380e 100644 --- a/src/bustapaga/buca02/BustaPagaTest.java +++ b/src/bustapaga/buca02/BustaPagaTest02.java @@ -3,7 +3,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest02 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { BustaPaga bustaPaga = new BustaPaga(5000); diff --git a/src/bustapaga/buca03/BustaPagaTest.java b/src/bustapaga/buca03/BustaPagaTest03.java similarity index 97% rename from src/bustapaga/buca03/BustaPagaTest.java rename to src/bustapaga/buca03/BustaPagaTest03.java index f57ed44..f1d0cae 100644 --- a/src/bustapaga/buca03/BustaPagaTest.java +++ b/src/bustapaga/buca03/BustaPagaTest03.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest03 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { BustaPaga bustaPaga = new BustaPaga(5000); diff --git a/src/bustapaga/buca04/BustaPagaTest.java b/src/bustapaga/buca04/BustaPagaTest04.java similarity index 97% rename from src/bustapaga/buca04/BustaPagaTest.java rename to src/bustapaga/buca04/BustaPagaTest04.java index 2bf7318..110187c 100644 --- a/src/bustapaga/buca04/BustaPagaTest.java +++ b/src/bustapaga/buca04/BustaPagaTest04.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest04 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { BustaPaga bustaPaga = new BustaPaga(5000, new CalcolatoreTasse()); diff --git a/src/bustapaga/buca05/BustaPagaTest.java b/src/bustapaga/buca05/BustaPagaTest05.java similarity index 97% rename from src/bustapaga/buca05/BustaPagaTest.java rename to src/bustapaga/buca05/BustaPagaTest05.java index 6ca6953..279c70f 100644 --- a/src/bustapaga/buca05/BustaPagaTest.java +++ b/src/bustapaga/buca05/BustaPagaTest05.java @@ -4,7 +4,7 @@ import org.junit.Test; -public class BustaPagaTest { +public class BustaPagaTest05 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { assertNettoDatoIlLordo(5000, 5000); diff --git a/src/bustapaga/buca06/BustaPagaTest.java b/src/bustapaga/buca06/BustaPagaTest06.java similarity index 97% rename from src/bustapaga/buca06/BustaPagaTest.java rename to src/bustapaga/buca06/BustaPagaTest06.java index b0fe0d4..4382fd5 100644 --- a/src/bustapaga/buca06/BustaPagaTest.java +++ b/src/bustapaga/buca06/BustaPagaTest06.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest06 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { assertNettoDatoIlLordo(5000, 5000); diff --git a/src/bustapaga/buca07/BustaPagaTest.java b/src/bustapaga/buca07/BustaPagaTest07.java similarity index 97% rename from src/bustapaga/buca07/BustaPagaTest.java rename to src/bustapaga/buca07/BustaPagaTest07.java index b478793..5f03f56 100644 --- a/src/bustapaga/buca07/BustaPagaTest.java +++ b/src/bustapaga/buca07/BustaPagaTest07.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest07 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { assertNettoDatoIlLordo(5000, 5000); diff --git a/src/bustapaga/buca08/BustaPagaTest.java b/src/bustapaga/buca08/BustaPagaTest08.java similarity index 97% rename from src/bustapaga/buca08/BustaPagaTest.java rename to src/bustapaga/buca08/BustaPagaTest08.java index 8799961..8e17a7c 100644 --- a/src/bustapaga/buca08/BustaPagaTest.java +++ b/src/bustapaga/buca08/BustaPagaTest08.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest08 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { assertNettoDatoIlLordo(5000, 5000); diff --git a/src/bustapaga/buca09/BustaPagaTaxTest.java b/src/bustapaga/buca09/BustaPagaTaxTest09.java similarity index 97% rename from src/bustapaga/buca09/BustaPagaTaxTest.java rename to src/bustapaga/buca09/BustaPagaTaxTest09.java index ae6d1d9..e80598c 100644 --- a/src/bustapaga/buca09/BustaPagaTaxTest.java +++ b/src/bustapaga/buca09/BustaPagaTaxTest09.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTaxTest { +public class BustaPagaTaxTest09 { @Test public void tasseZeroSeImponibileInferioreAlPrimoScaglione() { assertNettoDatoIlLordo(5000, 5000); diff --git a/src/bustapaga/buca09/BustaPagaTest.java b/src/bustapaga/buca09/BustaPagaTest09.java similarity index 90% rename from src/bustapaga/buca09/BustaPagaTest.java rename to src/bustapaga/buca09/BustaPagaTest09.java index 0e13cb0..2521d37 100644 --- a/src/bustapaga/buca09/BustaPagaTest.java +++ b/src/bustapaga/buca09/BustaPagaTest09.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest09 { @Test public void nettoÈImponibileMenoTasse() { final BustaPaga bustaPaga = new BustaPaga(5000, imponibile -> 500); diff --git a/src/bustapaga/buca10/BustaPagaTaxTest.java b/src/bustapaga/buca10/BustaPagaTaxTest10.java similarity index 97% rename from src/bustapaga/buca10/BustaPagaTaxTest.java rename to src/bustapaga/buca10/BustaPagaTaxTest10.java index 5b4b344..a743a8f 100644 --- a/src/bustapaga/buca10/BustaPagaTaxTest.java +++ b/src/bustapaga/buca10/BustaPagaTaxTest10.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTaxTest { +public class BustaPagaTaxTest10 { @Test public void taxIsZeroIfGrossIsBelowTaxFreeLimit() { assertNetForGross(5000, 5000); diff --git a/src/bustapaga/buca10/BustaPagaTest.java b/src/bustapaga/buca10/BustaPagaTest10.java similarity index 90% rename from src/bustapaga/buca10/BustaPagaTest.java rename to src/bustapaga/buca10/BustaPagaTest10.java index 2ce296e..30598da 100644 --- a/src/bustapaga/buca10/BustaPagaTest.java +++ b/src/bustapaga/buca10/BustaPagaTest10.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; -public class BustaPagaTest { +public class BustaPagaTest10 { @Test public void nettoÈImponibileMenoTasse() { final BustaPaga bustaPaga = new BustaPaga(5000, imponibile -> 500);