Skip to content

Instantly share code, notes, and snippets.

//Domain Entity responsible for calculating EMI for given params.
class EMICalculator
{
double? amount,rate,time;
}
void main()
{
test("Amount cannot be null",()
{
EMICalculator emiCalculator=EMICalculator();
//Performing assertion
expect(emiCalculator.amount,isNot(null), reason:"Amount cannot be null");
});
//Domain Entity responsible for calculating EMI for given params.
class EMICalculator {
final double amount, rate, time;
EMICalculator(this.amount, this.rate, this.time);
}
void main()
{
test("Amount cannot be null",()
{
EMICalculator emiCalculator=EMICalculator(1,2,3);
//Performing assertion
expect(emiCalculator.amount,isNot(null), reason:"Amount cannot be null");
});
//Domain Entity responsible for calculating EMI for given params.
class EMICalculator {
final double amount, rate, time;
EMICalculator(this.amount, this.rate, this.time);
double calculateEMI()
{
return -1;
}
void main()
{
test("EMI cannot be zero",()
{
EMICalculator emiCalculator=EMICalculator(1,2,3);
//Performing assertion
expect(emiCalculator.calculateEMI(),greaterThan(0),reason:"EMI calculated is zero");
});
}
class EMICalculator {
final double amount, rate, time;
EMICalculator(this.amount, this.rate, this.time);
double calculateEMI()
{
return amount*rate*(1 + rate)*time/((1+rate)*time-1);
}
}
class LoanParamRequest {
final double amount, time;
LoanParamRequest(this.amount, this.time);
}
class LoanDetailResponse {
String? _emi;
}
class MockedSucessRateFetchRepository extends ILoanRepository {
final LoanDetailDTO _mockedResponse;
MockedSucessRateFetchRepository(this._mockedResponse);
Future<LoanDetailDTO> getLoanFromServer(double amount, double time) {
return Future.value(this._mockedResponse);
}
}
test(
"Fetch loan should not fail with any exception when mocked with success response",
() {
FetchLoanDetail fetchLoanUseCase =
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO(3)));
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) {
}, expectAsync1((error) {
expect(error, isNot(isInstanceOf<UseCaseNotImplementedException>()),