Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioaniche committed Nov 14, 2011
0 parents commit 20d3ea9
Show file tree
Hide file tree
Showing 191 changed files with 15,541 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.class
Empty file added .metadata/.lock
Empty file.
16 changes: 16 additions & 0 deletions .metadata/.log
@@ -0,0 +1,16 @@
!SESSION 2011-11-14 11:24:39.615 -----------------------------------------------
eclipse.buildId=I20110613-1736
java.version=1.6.0_24
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=en_US
Framework arguments: -product org.eclipse.epp.package.jee.product -product org.eclipse.epp.package.jee.product -keyring /Users/mauricioaniche/.eclipse_keyring -showlocation
Command-line arguments: -os macosx -ws cocoa -arch x86 -product org.eclipse.epp.package.jee.product -data /Users/mauricioaniche/dev/workspace-tdd -product org.eclipse.epp.package.jee.product -keyring /Users/mauricioaniche/.eclipse_keyring -showlocation

!ENTRY org.eclipse.core.net 1 0 2011-11-14 11:24:46.272
!MESSAGE System property http.nonProxyHosts has been set to local|*.local|169.254/16|*.169.254/16 by an external source. This value will be overwritten using the values from the preferences

!ENTRY org.eclipse.mylyn.tasks.ui 4 0 2011-11-14 11:24:46.458
!MESSAGE Could not load repository template extension contributed by com.industriallogic.embunit.eclipse with connectorKind trac

!ENTRY org.eclipse.mylyn.tasks.ui 4 0 2011-11-14 11:24:46.459
!MESSAGE Could not load repository template extension contributed by com.industriallogic.gtest.eclipse with connectorKind trac
Binary file added .metadata/.mylyn/repositories.xml.zip
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions .metadata/.plugins/org.eclipse.cdt.make.core/specs.c
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions .metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp
@@ -0,0 +1 @@

@@ -0,0 +1,10 @@
package br.com.caelum.tdd.exercicio6;

import java.util.List;

public class ClosingIndicator{

public double calculate(int position, List<Candle> serie){
return serie.get(position).getClosing();
}
}
@@ -0,0 +1,40 @@
package br.com.caelum.tdd.exercicio6;

import java.util.Calendar;

public class Candle {

private double opening;
private double closing;
private double minimum;
private double maximum;
private Calendar date;

public Candle(double opening, double closing, double minimum,
double maximum, Calendar date) {
this.opening = opening;
this.closing = closing;
this.minimum = minimum;
this.maximum = maximum;
this.date = date;
}

public double getOpening() {
return opening;
}
public double getClosing() {
return closing;
}
public double getMinimum() {
return minimum;
}
public double getMaximum() {
return maximum;
}
public Calendar getDate() {
return date;
}



}
@@ -0,0 +1,25 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

public class MinimumIndicatorTests {

@Test
public void shouldReturnTheMinimumCandleValue() {
double amount = new MinimumIndicator().calculate(1, Arrays.asList(
candleWithMinimum(10.0), candleWithMinimum(12.0),
candleWithMinimum(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithMinimum(double minimum) {
return new Candle(0, 0, minimum, 0, Calendar.getInstance());
}
}
@@ -0,0 +1,28 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

import br.com.caelum.tdd.exercise6.Candle;
import br.com.caelum.tdd.exercise6.MinimumIndicator;

public class MinimumIndicatorTests {

@Test
public void shouldReturnTheMinimumCandleValue() {
double amount = new MinimumIndicator().calculate(1, Arrays.asList(
candleWithMinimum(10.0), candleWithMinimum(12.0),
candleWithMinimum(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithMinimum(double minimum) {
return new Candle(0, 0, minimum, 0, Calendar.getInstance());
}
}
@@ -0,0 +1,18 @@
package br.com.caelum.tdd.exercicio6;

import java.util.List;

public class WeightedMovingAverage{

public double calculate(int position, List<Candle> series, String type){
double sum = 0.0;
int weight = 1;

for(int i = position -2; i <= position; i++){
Candle c = series.get(i);
sum += (type.equals("opening")? c.getOpening() : c.getClosing())*weight;
weight++;
}
return sum/6;
}
}
@@ -0,0 +1,10 @@
package br.com.caelum.tdd.exercicio6;

import java.util.List;

public class MaximumIndicator{

public double calculate(int position, List<Candle> serie){
return serie.get(position).getMaximum();
}
}
@@ -0,0 +1,25 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

public class MaximumIndicatorTests {

@Test
public void shouldReturnTheMaximumCandleValue() {
double amount = new MaximumIndicator().calculate(1, Arrays.asList(
candleWithMaximum(10.0), candleWithMaximum(12.0),
candleWithMaximum(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithMaximum(double maximum) {
return new Candle(0, 0, 0, maximum, Calendar.getInstance());
}
}
@@ -0,0 +1,28 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

import br.com.caelum.tdd.exercise6.Candle;
import br.com.caelum.tdd.exercise6.OpeningIndicator;

public class OpeningIndicatorTests {

@Test
public void shouldReturnCandleOpeningValue() {
double amount = new OpeningIndicator().calculate(1, Arrays.asList(
candleWithOpening(10.0), candleWithOpening(12.0),
candleWithOpening(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithOpening(double opening) {
return new Candle(opening, 0, 0, 0, Calendar.getInstance());
}
}
@@ -0,0 +1,10 @@
package br.com.caelum.tdd.exercicio6;

import java.util.List;

public class MinimumIndicator{

public double calculate(int position, List<Candle> serie){
return serie.get(position).getMinimum();
}
}
@@ -0,0 +1,28 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

import br.com.caelum.tdd.exercise6.Candle;
import br.com.caelum.tdd.exercise6.ClosingIndicator;

public class ClosingIndicatorTests {

@Test
public void shouldReturnClosingCandleValue() {
double amount = new ClosingIndicator().calculate(1, Arrays.asList(
candleWithClosing(10.0), candleWithClosing(12.0),
candleWithClosing(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithClosing(double closing) {
return new Candle(0, closing, 0, 0, Calendar.getInstance());
}
}
@@ -0,0 +1,40 @@
package br.com.gnarus.tdd.exercise5;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import br.com.gnarus.tdd.exercise5.RegularBankAccount;

public class RegularBankAccountTests {

@Test
public void shouldDepositAmount() {
RegularBankAccount account = new RegularBankAccount();

account.deposit(1000.0);
assertEquals(1000, account.getBalance(), 0.00001);

account.deposit(500.5);
assertEquals(1500.5, account.getBalance(), 0.00001);
}


public void shouldWithDrawIfAmountIsLessThanTheAvailableBalance() {
RegularBankAccount account = new RegularBankAccount();
account.deposit(1000.0);

account.withdraw(900);

assertEquals(100.0, account.getBalance(), 0.00001);
}

@Test(expected=IllegalArgumentException.class)
public void shouldForbitWithdrawIfRequestedAmountIsGreaterThanCurrentBalance() {
RegularBankAccount account = new RegularBankAccount();
account.deposit(1000.0);

account.withdraw(2000.0);
}

}
@@ -0,0 +1,10 @@
package br.com.caelum.tdd.exercicio6;

import java.util.List;

public class OpeningIndicator{

public double calculate(int position, List<Candle> serie){
return serie.get(position).getOpening();
}
}
@@ -0,0 +1,28 @@
package br.com.caelum.tdd.exercicio6;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Calendar;

import org.junit.Test;

import br.com.caelum.tdd.exercise6.Candle;
import br.com.caelum.tdd.exercise6.MaximumIndicator;

public class MaximumIndicatorTests {

@Test
public void shouldReturnTheMaximumCandleValue() {
double amount = new MaximumIndicator().calculate(1, Arrays.asList(
candleWithMaximum(10.0), candleWithMaximum(12.0),
candleWithMaximum(11.0)));

assertEquals(12.0, amount, 0.00001);

}

private Candle candleWithMaximum(double maximum) {
return new Candle(0, 0, 0, maximum, Calendar.getInstance());
}
}
@@ -0,0 +1,43 @@
package br.com.caelum.tdd.exercise3;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Test;

import br.com.caelum.tdd.exercise3.Bankslip;
import br.com.caelum.tdd.exercise3.BankslipProcessor;
import br.com.caelum.tdd.exercise3.Invoice;
import br.com.caelum.tdd.exercise3.Payment;
import br.com.caelum.tdd.exercise3.PaymentMethod;

public class BankslipProcessorTest {

@Test
public void shouldNotGeneratePaymentWhenThereIsNoBankslips() {
Invoice invoice = new Invoice("caelum", 1000.0);
List<Bankslip> paidBankslips = Collections.emptyList();

new BankslipProcessor().process(paidBankslips, invoice);

assertEquals(0, invoice.getPayments().size());
}

@Test
public void shouldGenerateABankslipPaymentForAnInvoice() {
Invoice invoice = new Invoice("caelum", 1000.0);
List<Bankslip> paidBankslips = Arrays.asList(new Bankslip(200.0), new Bankslip(500.0));

new BankslipProcessor().process(paidBankslips, invoice);

assertEquals(2, invoice.getPayments().size());
assertEquals(new Payment(200.0, PaymentMethod.BANKSLIP), invoice.getPayments().get(0));
assertEquals(new Payment(500.0, PaymentMethod.BANKSLIP), invoice.getPayments().get(1));
}


}

0 comments on commit 20d3ea9

Please sign in to comment.