Permalink
Browse files

Adicionando calculo de FDS

  • Loading branch information...
phstc committed Apr 21, 2012
1 parent 44e8552 commit 449be13ebdf959d264c5ba5810fbb490cd13f34a
Showing with 27 additions and 11 deletions.
  1. +14 −10 BilheteUnico.dart
  2. +13 −1 BilheteUnicoTest.dart
View
@@ -1,31 +1,35 @@
class BilheteUnico {
double saldo = 0.0;
double valorDiaUtil = 0.0;
+ double valorDiaFds = 0.0;
- BilheteUnico(double saldo, double valorDiaUtil){
+ BilheteUnico(double saldo, double valorDiaUtil, [double valorDiaFds = 0.0]){
this.saldo = saldo;
- this.valorDiaUtil= valorDiaUtil;
+ this.valorDiaUtil = valorDiaUtil;
+ this.valorDiaFds = valorDiaFds;
}
void adicionaSaldo(double newSaldo){
- this.saldo += newSaldo;
+ saldo += newSaldo;
}
Date proximaRecarga([Date now]){
if(now == null){
now = new Date.now().add(new Duration(1));
}
- double diasXsaldo = saldo / valorDiaUtil;
- Date next = now;
- for(int i = 1; i <= diasXsaldo; i++){
- Date currDate = now.add(new Duration(i));
- if(currDate.weekday != Date.SAT && currDate.weekday != Date.SUN){
- next = next.add(new Duration(1));
+ double currSaldo = saldo;
+ Date currDate = now;
+ while(currSaldo >= valorDiaUtil){
+ currDate = currDate.add(new Duration(1));
+ if(currDate.weekday == Date.SAT && currDate.weekday == Date.SUN){
+ currSaldo -= valorDiaFds;
+ } else {
+ currSaldo -= valorDiaUtil;
}
}
- return next;
+ return currDate;
}
toString(){
View
@@ -11,7 +11,8 @@ class BilheteUnicoTest {
[testIncialVariaveis,
testIncrementaSaldo,
testDecrementaSaldo,
- testCalculaProximaRecarga].forEach(beforeEach);
+ testCalculaProximaRecarga,
+ testCalculaProximaRecargaComFDS].forEach(beforeEach);
}
static void beforeEach(var test){
@@ -44,6 +45,17 @@ class BilheteUnicoTest {
Expect.equals(4, proximaRecarga.month);
Expect.equals(3, proximaRecarga.day);
}
+
+ static void testCalculaProximaRecargaComFDS(){
+ bu.saldo = 30.0;
+ bu.valorDiaUtil = 6.0;
+ bu.valorDiaFds = 3.0;
+ Date now = new Date(2012, 4, 1, 0, 0, 0, 0);
+ Date proximaRecarga = bu.proximaRecarga(now);
+ Expect.equals(2012, proximaRecarga.year);
+ Expect.equals(4, proximaRecarga.month);
+ Expect.equals(6, proximaRecarga.day);
+ }
}
void main() {

0 comments on commit 449be13

Please sign in to comment.