Last active
September 8, 2021 15:26
-
-
Save PreyeaRegmi/2d4739c264e2d1bac7d30e9292c79f5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Domain Entity responsible for calculating EMI for given params. | |
class EMICalculator { | |
final double amount, rate, time; | |
EMICalculator(this.amount, this.rate, this.time){ | |
if(amount<0) | |
throw ArgumentError("Amount cannot be less than zero"); | |
if(rate<0) | |
throw ArgumentError("Rate cannot be less than zero"); | |
if(time<0) | |
throw ArgumentError("Time cannot be less than zero"); | |
} | |
//EMI = amount× rate × (1 + rate)time/((1 + rate)time-1). | |
double calculateEMI() | |
{ | |
return amount*rate*(1 + rate)*time/((1+rate)*time-1); | |
} | |
} | |
//TEST CASES | |
test("Amount cannot be null",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.amount,isNot(null), reason:"Amount cannot be null"); | |
}); | |
test("Rate cannot be null",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.rate,isNot(null),reason:"Rate cannot be null"); | |
}); | |
test("Rate cannot be null",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.time,isNot(null),reason:"Time cannot be null"); | |
}); | |
test("EMI cannot be negative",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.calculateEMI(),greaterThan(0),reason:"EMI cannot be negative"); | |
}); | |
test("Amount cannot be negative",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1000,12,3); | |
//Performing assertion | |
expect(emiCalculator.rate,greaterThan(-1),reason:"Amount cannot be negative"); | |
}); | |
test("Rate cannot be negative",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.rate,greaterThan(-1),reason:"Rate cannot be negative"); | |
}); | |
test("Time cannot be negative",() | |
{ | |
EMICalculator emiCalculator=EMICalculator(1,2,3); | |
//Performing assertion | |
expect(emiCalculator.rate,greaterThan(-1),reason:"Rate cannot be negative"); | |
}); | |
test("EMI must 150391.64490861617 for amount =10,000 , rate = 15, time =24 months",(){ | |
EMICalculator emiCalculator=EMICalculator(10000,15,24); | |
//We are asserting factual data with our implemented behavior | |
expect(150391.64490861617,equals( emiCalculator.calculateEMI()),reason: "Emi calculation invalid"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment