diff --git a/android-app/app/src/test/java/com/dienstplan/nrw/PayrollCalculatorTest.kt b/android-app/app/src/test/java/com/dienstplan/nrw/PayrollCalculatorTest.kt index 2403c0f..dbabf20 100644 --- a/android-app/app/src/test/java/com/dienstplan/nrw/PayrollCalculatorTest.kt +++ b/android-app/app/src/test/java/com/dienstplan/nrw/PayrollCalculatorTest.kt @@ -52,7 +52,7 @@ class PayrollCalculatorTest { /** * Test Case 2: Exactly at threshold (2.0 WE) - * Expected: WE payout = 450€ (1.0 unit after deduction), threshold reached + * Expected: WE payout = 0€ (0.0 units after deduction), threshold reached */ @Test fun testExactlyAtThreshold() { @@ -67,14 +67,14 @@ class PayrollCalculatorTest { val result = results[0] assertEquals(2.0, result.weTotal, 0.001) assertTrue(result.thresholdReached) - assertEquals(1.0, result.deductionTotal, 0.001) - assertEquals(1.0, result.wePaid, 0.001) - assertEquals(450.0, result.payoutWE, 0.001) + assertEquals(2.0, result.deductionTotal, 0.001) + assertEquals(0.0, result.wePaid, 0.001) + assertEquals(0.0, result.payoutWE, 0.001) } /** * Test Case 3: Over threshold (3.5 WE) - * Expected: WE payout = 1125€ (2.5 units after deduction) + * Expected: WE payout = 675€ (1.5 units after deduction) */ @Test fun testOverThreshold() { @@ -91,8 +91,8 @@ class PayrollCalculatorTest { val result = results[0] assertEquals(3.5, result.weTotal, 0.001) assertTrue(result.thresholdReached) - assertEquals(2.5, result.wePaid, 0.001) - assertEquals(1125.0, result.payoutWE, 0.001) + assertEquals(1.5, result.wePaid, 0.001) + assertEquals(675.0, result.payoutWE, 0.001) } /** @@ -115,8 +115,8 @@ class PayrollCalculatorTest { assertEquals(0.4, result.weFriday, 0.001) assertEquals(1.6, result.weOther, 0.001) assertEquals(0.4, result.deductionFriday, 0.001) // All Friday deducted first - assertEquals(0.6, result.deductionOther, 0.001) // Rest from other - assertEquals(1.0, result.wePaid, 0.001) + assertEquals(1.6, result.deductionOther, 0.001) // Rest from other (1.6 to reach 2.0 total) + assertEquals(0.0, result.wePaid, 0.001) } /** @@ -147,8 +147,8 @@ class PayrollCalculatorTest { // B: above threshold assertTrue(resultB.thresholdReached) assertEquals(2.5, resultB.weTotal, 0.001) - assertEquals(1.5, resultB.wePaid, 0.001) - assertEquals(675.0, resultB.payoutWE, 0.001) + assertEquals(0.5, resultB.wePaid, 0.001) + assertEquals(225.0, resultB.payoutWE, 0.001) } private fun parseDate(dateString: String): Date { diff --git a/test_deduction.py b/test_deduction.py new file mode 100644 index 0000000..b09ecfc --- /dev/null +++ b/test_deduction.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +""" +Test script to verify the weekend deduction change from 1.0 to 2.0 units. +""" + +from datetime import date +import sys +sys.path.insert(0, 'src') +from calculate import calculate_verguetung + +# Test case 1: Exactly 2.0 WE units (threshold reached) +# Expected: 2.0 WE - 2.0 deduction = 0.0 paid → 0€ for WE +print("=" * 60) +print("Test 1: Exactly 2.0 WE units (threshold reached)") +print("=" * 60) + +holidays = set() +plan_data = [ + (date(2025, 11, 7), "Alice"), # Friday (WE) + (date(2025, 11, 8), "Alice"), # Saturday (WE) +] + +results = calculate_verguetung(plan_data, holidays) +alice = results[0] +print(f"Employee: {alice['mitarbeiter']}") +print(f"WE Friday: {alice['we_freitag']}") +print(f"WE Other: {alice['we_andere']}") +print(f"WE Total: {alice['we_gesamt']}") +print(f"Threshold reached: {alice['schwelle_erreicht']}") +print(f"WE paid: {alice['we_bezahlt']}") +print(f"Payout WE: {alice['auszahlung_we']}€") +print(f"Payout Total: {alice['auszahlung_gesamt']}€") + +if alice['we_gesamt'] == 2.0 and alice['we_bezahlt'] == 0.0 and alice['auszahlung_we'] == 0: + print("✅ PASS: Correctly deducts 2.0 WE units, resulting in 0€") +else: + print(f"❌ FAIL: Expected 0€ for WE, got {alice['auszahlung_we']}€") + +# Test case 2: 3.0 WE units +# Expected: 3.0 WE - 2.0 deduction = 1.0 paid → 450€ +print("\n" + "=" * 60) +print("Test 2: 3.0 WE units") +print("=" * 60) + +plan_data = [ + (date(2025, 11, 7), "Bob"), # Friday (WE) + (date(2025, 11, 8), "Bob"), # Saturday (WE) + (date(2025, 11, 9), "Bob"), # Sunday (WE) +] + +results = calculate_verguetung(plan_data, holidays) +bob = results[0] +print(f"Employee: {bob['mitarbeiter']}") +print(f"WE Friday: {bob['we_freitag']}") +print(f"WE Other: {bob['we_andere']}") +print(f"WE Total: {bob['we_gesamt']}") +print(f"Threshold reached: {bob['schwelle_erreicht']}") +print(f"WE paid: {bob['we_bezahlt']}") +print(f"Payout WE: {bob['auszahlung_we']}€") +print(f"Payout Total: {bob['auszahlung_gesamt']}€") + +if bob['we_gesamt'] == 3.0 and bob['we_bezahlt'] == 1.0 and bob['auszahlung_we'] == 450: + print("✅ PASS: Correctly deducts 2.0 WE units, resulting in 450€") +else: + print(f"❌ FAIL: Expected 450€ for WE, got {bob['auszahlung_we']}€") + +# Test case 3: 1.0 WE unit (below threshold) +# Expected: No payment (threshold not reached) +print("\n" + "=" * 60) +print("Test 3: 1.0 WE units (below threshold)") +print("=" * 60) + +plan_data = [ + (date(2025, 11, 8), "Charlie"), # Saturday (WE) +] + +results = calculate_verguetung(plan_data, holidays) +charlie = results[0] +print(f"Employee: {charlie['mitarbeiter']}") +print(f"WE Total: {charlie['we_gesamt']}") +print(f"Threshold reached: {charlie['schwelle_erreicht']}") +print(f"WE paid: {charlie['we_bezahlt']}") +print(f"Payout WE: {charlie['auszahlung_we']}€") +print(f"Payout Total: {charlie['auszahlung_gesamt']}€") + +if charlie['we_gesamt'] == 1.0 and charlie['we_bezahlt'] == 0.0 and charlie['auszahlung_we'] == 0: + print("✅ PASS: Below threshold, no payment") +else: + print(f"❌ FAIL: Expected 0€, got {charlie['auszahlung_we']}€") + +# Test case 4: Mixed WT and WE (2 WT + 2 WE) +# Expected: WT always paid (500€), WE: 2.0 - 2.0 = 0 paid (0€), Total: 500€ +print("\n" + "=" * 60) +print("Test 4: 2.0 WT + 2.0 WE units") +print("=" * 60) + +plan_data = [ + (date(2025, 11, 3), "Diana"), # Monday (WT) + (date(2025, 11, 4), "Diana"), # Tuesday (WT) + (date(2025, 11, 7), "Diana"), # Friday (WE) + (date(2025, 11, 8), "Diana"), # Saturday (WE) +] + +results = calculate_verguetung(plan_data, holidays) +diana = results[0] +print(f"Employee: {diana['mitarbeiter']}") +print(f"WT units: {diana['wt_einheiten']}") +print(f"WE Total: {diana['we_gesamt']}") +print(f"Threshold reached: {diana['schwelle_erreicht']}") +print(f"WE paid: {diana['we_bezahlt']}") +print(f"Payout WT: {diana['auszahlung_wt']}€") +print(f"Payout WE: {diana['auszahlung_we']}€") +print(f"Payout Total: {diana['auszahlung_gesamt']}€") + +if diana['wt_einheiten'] == 2.0 and diana['auszahlung_wt'] == 500 and diana['we_bezahlt'] == 0.0 and diana['auszahlung_we'] == 0 and diana['auszahlung_gesamt'] == 500: + print("✅ PASS: WT paid (500€), WE deducted completely (0€), Total: 500€") +else: + print(f"❌ FAIL: Expected total 500€, got {diana['auszahlung_gesamt']}€") + +print("\n" + "=" * 60) +print("Test Summary") +print("=" * 60) +print("All tests verify that the deduction is now 2.0 WE units (not 1.0)") +print("This matches the business requirement from the issue.") diff --git a/webapp/test-suite.js b/webapp/test-suite.js index 4fff30b..03e85a9 100644 --- a/webapp/test-suite.js +++ b/webapp/test-suite.js @@ -204,9 +204,9 @@ runner.test('Berechnung: Genau 2.0 WE-Tage = 450€', (t) => { t.assertEqual(result.qualifyingDays, 2.0, 'Sollte 2.0 qualifizierende Tage haben'); t.assertTrue(result.thresholdReached, 'Schwellenwert sollte erreicht sein'); - t.assertEqual(result.qualifyingDaysDeducted, 1.0, 'Sollte 1.0 Tag abziehen'); - t.assertEqual(result.qualifyingDaysPaid, 1.0, 'Sollte 1.0 Tag bezahlen'); - t.assertEqual(result.totalBonus, 450, 'Bonus sollte 450€ sein'); + t.assertEqual(result.qualifyingDaysDeducted, 2.0, 'Sollte 2.0 Tage abziehen'); + t.assertEqual(result.qualifyingDaysPaid, 0.0, 'Sollte 0.0 Tage bezahlen'); + t.assertEqual(result.totalBonus, 0, 'Bonus sollte 0€ sein'); }); runner.test('Berechnung: 2x halbe WE-Dienste = 0€ (genau Schwelle, aber nach Abzug nichts)', (t) => { @@ -224,11 +224,11 @@ runner.test('Berechnung: 2x halbe WE-Dienste = 0€ (genau Schwelle, aber nach A t.assertEqual(result.qualifyingDays, 2.0, 'Sollte 2.0 qualifizierende Tage haben (4×0.5)'); t.assertTrue(result.thresholdReached, 'Schwellenwert sollte erreicht sein'); - t.assertEqual(result.qualifyingDaysPaid, 1.0, 'Sollte 1.0 Tag bezahlen nach Abzug'); - t.assertEqual(result.totalBonus, 450, 'Bonus sollte 450€ sein'); + t.assertEqual(result.qualifyingDaysPaid, 0.0, 'Sollte 0.0 Tage bezahlen nach Abzug'); + t.assertEqual(result.totalBonus, 0, 'Bonus sollte 0€ sein'); }); -runner.test('Berechnung: 3 WE-Tage = 900€', (t) => { +runner.test('Berechnung: 3 WE-Tage = 450€', (t) => { const holidays = new HolidayProvider(); const calculator = new BonusCalculator(holidays); @@ -241,8 +241,8 @@ runner.test('Berechnung: 3 WE-Tage = 900€', (t) => { const result = calculator.calculateMonthlyBonus(duties); t.assertEqual(result.qualifyingDays, 3.0, 'Sollte 3.0 qualifizierende Tage haben'); - t.assertEqual(result.qualifyingDaysPaid, 2.0, 'Sollte 2.0 Tage bezahlen (3-1)'); - t.assertEqual(result.totalBonus, 900, 'Bonus sollte 900€ sein (2×450€)'); + t.assertEqual(result.qualifyingDaysPaid, 1.0, 'Sollte 1.0 Tag bezahlen (3-2)'); + t.assertEqual(result.totalBonus, 450, 'Bonus sollte 450€ sein (1×450€)'); }); runner.test('Berechnung: Normale Tage + WE-Tage gemischt', (t) => { @@ -261,10 +261,10 @@ runner.test('Berechnung: Normale Tage + WE-Tage gemischt', (t) => { t.assertEqual(result.normalDays, 2.0, 'Sollte 2.0 normale Tage haben'); t.assertEqual(result.qualifyingDays, 2.0, 'Sollte 2.0 qualifizierende Tage haben'); t.assertEqual(result.normalDaysPaid, 2.0, 'Sollte 2.0 normale Tage bezahlen'); - t.assertEqual(result.qualifyingDaysPaid, 1.0, 'Sollte 1.0 qualifizierenden Tag bezahlen'); + t.assertEqual(result.qualifyingDaysPaid, 0.0, 'Sollte 0.0 qualifizierenden Tag bezahlen'); t.assertEqual(result.bonusNormalDays, 500, 'Normale Tage: 2×250€ = 500€'); - t.assertEqual(result.bonusQualifyingDays, 450, 'WE-Tage: 1×450€ = 450€'); - t.assertEqual(result.totalBonus, 950, 'Gesamt: 950€'); + t.assertEqual(result.bonusQualifyingDays, 0, 'WE-Tage: 0×450€ = 0€'); + t.assertEqual(result.totalBonus, 500, 'Gesamt: 500€'); }); runner.test('Berechnung: Halbe Dienste korrekt berechnet', (t) => { @@ -282,10 +282,10 @@ runner.test('Berechnung: Halbe Dienste korrekt berechnet', (t) => { t.assertEqual(result.normalDays, 0.5, 'Sollte 0.5 normale Tage haben'); t.assertEqual(result.qualifyingDays, 2.5, 'Sollte 2.5 qualifizierende Tage haben'); - t.assertEqual(result.qualifyingDaysPaid, 1.5, 'Sollte 1.5 qualifizierende Tage bezahlen'); + t.assertEqual(result.qualifyingDaysPaid, 0.5, 'Sollte 0.5 qualifizierende Tage bezahlen'); t.assertEqual(result.bonusNormalDays, 125, 'Normale Tage: 0.5×250€ = 125€'); - t.assertEqual(result.bonusQualifyingDays, 675, 'WE-Tage: 1.5×450€ = 675€'); - t.assertEqual(result.totalBonus, 800, 'Gesamt: 800€'); + t.assertEqual(result.bonusQualifyingDays, 225, 'WE-Tage: 0.5×450€ = 225€'); + t.assertEqual(result.totalBonus, 350, 'Gesamt: 350€'); }); runner.test('Berechnung: Feiertag + Vortag', (t) => { @@ -301,7 +301,7 @@ runner.test('Berechnung: Feiertag + Vortag', (t) => { t.assertEqual(result.qualifyingDays, 2.0, 'Sollte 2.0 qualifizierende Tage haben'); t.assertTrue(result.thresholdReached, 'Schwellenwert sollte erreicht sein'); - t.assertEqual(result.totalBonus, 450, 'Bonus sollte 450€ sein'); + t.assertEqual(result.totalBonus, 0, 'Bonus sollte 0€ sein'); }); runner.test('Berechnung: Keine Dienste = 0€', (t) => {