Skip to content

Commit

Permalink
Refactory temSaldo
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Cantero committed Apr 23, 2012
1 parent c4ce092 commit d1ddb6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
9 changes: 8 additions & 1 deletion BilheteUnico.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ class BilheteUnico {
}


bool temSaldo([double currSaldo]){
if(currSaldo == null){
currSaldo = saldo;
}
return currSaldo > valorDiaFds && currSaldo > valorDiaUtil;
}

Date proximaRecarga([Date now]){
if(now == null){
now = new Date.now().add(new Duration(1));
}
double currSaldo = saldo;
Date currDate = now;
while(currSaldo > valorDiaFds && currSaldo > valorDiaUtil){
while(temSaldo(currSaldo)){
if(currDate.weekday == Date.SAT || currDate.weekday == Date.SUN){
currSaldo -= valorDiaFds;
} else {
Expand Down
34 changes: 33 additions & 1 deletion BilheteUnicoTest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class BilheteUnicoTest {
testIncrementaSaldo,
testDecrementaSaldo,
testCalculaProximaRecarga,
testCalculaProximaRecargaComFDS].forEach(beforeEach);
testCalculaProximaRecargaComFDS,
testTemSaldoDiaUtil,
testTemSaldoDiaFds,
testNaoTemSaldoDiaUtil,
testNaoTemSaldoDiaFds].forEach(beforeEach);
}

static void beforeEach(var test){
Expand Down Expand Up @@ -47,6 +51,34 @@ class BilheteUnicoTest {
Expect.equals(4, proximaRecarga.day);
}

static void testTemSaldoDiaUtil(){
bu.saldo = 7.0;
bu.valorDiaUtil = 6.0;
bu.valorDiaFds = 0.0;
Expect.isTrue(bu.temSaldo());
}

static void testTemSaldoDiaFds(){
bu.saldo = 7.0;
bu.valorDiaUtil = 0.0;
bu.valorDiaFds = 6.0;
Expect.isTrue(bu.temSaldo());
}

static void testNaoTemSaldoDiaUtil(){
bu.saldo = 3.0;
bu.valorDiaUtil = 6.0;
bu.valorDiaFds = 0.0;
Expect.isFalse(bu.temSaldo());
}

static void testNaoTemSaldoDiaFds(){
bu.saldo = 3.0;
bu.valorDiaUtil = 0.0;
bu.valorDiaFds = 6.0;
Expect.isFalse(bu.temSaldo());
}

static void testCalculaProximaRecargaComFDS(){
bu.saldo = 30.0;
bu.valorDiaUtil = 6.0;
Expand Down

0 comments on commit d1ddb6c

Please sign in to comment.