Compare commits
No commits in common. "master" and "feedback" have entirely different histories.
|
@ -1,8 +1,6 @@
|
|||
package ch.zhaw.prog2.functional.stepik;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public class ComposingPredicate {
|
||||
|
@ -13,8 +11,7 @@ public class ComposingPredicate {
|
|||
* @see #disjunctAllNoStream(List)
|
||||
*/
|
||||
public static IntPredicate disjunctAll(List<IntPredicate> predicates) {
|
||||
// TODO: remove this line and implement your solution
|
||||
return i -> predicates.stream().anyMatch(p -> p.test(i));
|
||||
throw new UnsupportedOperationException(); // TODO: remove this line and implement your solution
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,6 @@ package ch.zhaw.prog2.functional.streaming;
|
|||
import ch.zhaw.prog2.functional.streaming.finance.CurrencyAmount;
|
||||
import ch.zhaw.prog2.functional.streaming.finance.Payment;
|
||||
import ch.zhaw.prog2.functional.streaming.humanresource.Employee;
|
||||
import ch.zhaw.prog2.functional.streaming.humanresource.Person;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -41,14 +40,14 @@ public class Company {
|
|||
* Aufgabe a1)
|
||||
*/
|
||||
public List<String> getDistinctFirstnamesOfEmployees() {
|
||||
return employeeList.stream().map(Person::getFirstName).distinct().toList();
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Aufgabe a2)
|
||||
*/
|
||||
public String[] getDistinctLastnamesOfEmployees() {
|
||||
return employeeList.stream().map(Person::getLastName).distinct().toArray(String[]::new);
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -56,14 +55,14 @@ public class Company {
|
|||
* There might be Employees not working for the Company (e.g. temporally)
|
||||
*/
|
||||
public List<Employee> getEmployeesWorkingForCompany() {
|
||||
return employeeList.stream().filter(Employee::isWorkingForCompany).toList();
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Aufgabe c) - Test in Klasse CompanyTestStudent
|
||||
*/
|
||||
public List<Employee> getEmployeesByPredicate(Predicate<Employee> filterPredicate) {
|
||||
return employeeList.stream().filter(filterPredicate).toList();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,13 +99,7 @@ public class Company {
|
|||
* @return a List of Payments based on predicate and payment function
|
||||
*/
|
||||
public List<Payment> getPayments(Predicate<Employee> employeePredicate, Function<Employee, Payment> paymentForEmployee) {
|
||||
List<Payment> paymentList = new ArrayList<>();
|
||||
for(Employee employee: employeeList) {
|
||||
if (employeePredicate.test(employee)) {
|
||||
paymentList.add(paymentForEmployee.apply(employee));
|
||||
}
|
||||
}
|
||||
return paymentList;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,12 +108,7 @@ public class Company {
|
|||
* Function calculating Payment for January.
|
||||
*/
|
||||
public static final Function<Employee, Payment> paymentForEmployeeJanuary = employee -> {
|
||||
Payment payment = new Payment();
|
||||
CurrencyAmount salary = employee.getYearlySalary();
|
||||
int paymentsPerYear = employee.getPaymentsPerYear().getValue();
|
||||
salary = salary.createModifiedAmount(amount -> amount / paymentsPerYear);
|
||||
payment.setCurrencyAmount(salary).setBeneficiary(employee).setTargetAccount(employee.getAccount());
|
||||
return payment;
|
||||
return null;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -129,11 +117,6 @@ public class Company {
|
|||
* Fuction calculating Payment for December, where Employees having 13 Payments per year will get the double amount.
|
||||
*/
|
||||
public static final Function<Employee, Payment> paymentForEmployeeDecember = employee -> {
|
||||
Payment payment = new Payment();
|
||||
CurrencyAmount salary = employee.getYearlySalary();
|
||||
int paymentsPerYear = employee.getPaymentsPerYear().getValue();
|
||||
salary = salary.createModifiedAmount(amount -> paymentsPerYear == 13 ? amount * 2 / paymentsPerYear : amount / paymentsPerYear);
|
||||
payment.setCurrencyAmount(salary).setBeneficiary(employee).setTargetAccount(employee.getAccount());
|
||||
return payment;
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package ch.zhaw.prog2.functional.streaming.finance;
|
||||
|
||||
import ch.zhaw.prog2.functional.streaming.Company;
|
||||
import ch.zhaw.prog2.functional.streaming.humanresource.Employee;
|
||||
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* This Class creates a Payroll (Lohabrechnung) for a whole Company
|
||||
|
@ -27,16 +24,14 @@ public class PayrollCreator {
|
|||
* Aufgabe d) - Test dazu exisitert in PayrollCreatorTest
|
||||
*/
|
||||
public Payroll getPayrollForAll() {
|
||||
Payroll payroll = new Payroll();
|
||||
payroll.addPayments(company.getPayments(Employee::isWorkingForCompany));
|
||||
return payroll;
|
||||
return new Payroll();
|
||||
}
|
||||
|
||||
/*
|
||||
* Aufgabe e) - Test dazu existiert in PayrollCreatorTest
|
||||
*/
|
||||
public static int payrollValueCHF(Payroll payroll) {
|
||||
return payroll.stream().map(payment -> CurrencyChange.getInNewCurrency(payment.getCurrencyAmount(), Currency.getInstance("CHF")).getAmount()).reduce(Integer::sum).orElse(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,17 +39,7 @@ public class PayrollCreator {
|
|||
* @return a List of total amounts in this currency for each currency in the payroll
|
||||
*/
|
||||
public static List<CurrencyAmount> payrollAmountByCurrency(Payroll payroll) {
|
||||
List<CurrencyAmount> currencyAmounts = payroll.stream().map(Payment::getCurrencyAmount).toList();
|
||||
return currencyAmounts.stream()
|
||||
.map(CurrencyAmount::getCurrency)
|
||||
.distinct()
|
||||
.map(currency -> new CurrencyAmount(
|
||||
currencyAmounts.stream()
|
||||
.filter(currencyAmount -> currencyAmount.getCurrency().equals(currency))
|
||||
.map(CurrencyAmount::getAmount)
|
||||
.reduce(Integer::sum)
|
||||
.orElse(0), currency))
|
||||
.toList();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.junit.jupiter.api.BeforeEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -30,8 +29,7 @@ public class CompanyTestStudent {
|
|||
*/
|
||||
@Test
|
||||
void getEmployeesByPredicate() {
|
||||
Predicate<Employee> predicate = Employee::isFemale;
|
||||
assertEquals(testCompany.getAllEmployees().size(), testCompany.getEmployeesByPredicate(predicate).size() + testCompany.getEmployeesByPredicate(predicate.negate()).size());
|
||||
// TODO write your test
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,17 +1,5 @@
|
|||
package ch.zhaw.prog2.functional.streaming.finance;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Currency.getInstance;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* This test class is for all test methods written by students for easier review by lecturers.
|
||||
|
@ -19,44 +7,6 @@ import static org.mockito.Mockito.*;
|
|||
*
|
||||
* ✅ This class should be worked on by students.
|
||||
*/
|
||||
class PayrollCreatorTestStudent {
|
||||
Payroll payroll;
|
||||
|
||||
@BeforeEach
|
||||
void setup(){
|
||||
payroll = new Payroll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void payrollAmountByCurrency() {
|
||||
|
||||
Payroll payroll = mock(Payroll.class);
|
||||
|
||||
List<Payment> payments = new ArrayList<>();
|
||||
for(int i = 0; i < 3; i++){
|
||||
payments.add(mock(Payment.class));
|
||||
}
|
||||
|
||||
List<CurrencyAmount> currencyAmounts = new ArrayList<>();
|
||||
for(int i = 0; i < 3; i++){
|
||||
currencyAmounts.add(mock(CurrencyAmount.class));
|
||||
when(payments.get(i).getCurrencyAmount()).thenReturn(currencyAmounts.get(i));
|
||||
}
|
||||
|
||||
when(payroll.stream()).thenReturn(payments.stream());
|
||||
|
||||
when(currencyAmounts.get(0).getCurrency()).thenReturn(getInstance("CHF"));
|
||||
when(currencyAmounts.get(0).getAmount()).thenReturn(10);
|
||||
|
||||
when(currencyAmounts.get(1).getCurrency()).thenReturn(getInstance("CHF"));
|
||||
when(currencyAmounts.get(1).getAmount()).thenReturn(15);
|
||||
|
||||
when(currencyAmounts.get(2).getCurrency()).thenReturn(getInstance("USD"));
|
||||
when(currencyAmounts.get(2).getAmount()).thenReturn(117);
|
||||
|
||||
List<CurrencyAmount> sumCurrencyAmounts = PayrollCreator.payrollAmountByCurrency(payroll);
|
||||
assertEquals(25, sumCurrencyAmounts.stream().filter(currencyAmount -> currencyAmount.getCurrency().equals(getInstance("CHF"))).findFirst().get().getAmount());
|
||||
assertEquals(117, sumCurrencyAmounts.stream().filter(currencyAmount -> currencyAmount.getCurrency().equals(getInstance("USD"))).findFirst().get().getAmount());
|
||||
public class PayrollCreatorTestStudent {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue