Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 1ddc13f7cba054722fa8474edab0cd0e1c09c02b @Turini Turini committed Oct 10, 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main"/>
+ <classpathentry kind="src" path="src/teste"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>pm-75-leiloes</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
+<project name="pm-75-leiloes" default="gerar-jar">
+
+ <path id="tests.classpath" path=".">
+ <fileset dir="lib/">
+ <include name="*.jar" />
+ </fileset>
+ <pathelement path="classes/" />
+ </path>
+
+ <target name="compilar">
+ <mkdir dir="classes/"/>
+ <mkdir dir="classes-teste/"/>
+ <javac destdir="classes/" srcdir="src/main/" debug="true" encoding="UTF-8" />
+ <javac destdir="classes-teste/" srcdir="src/teste/" classpathref="tests.classpath" debug="true" encoding="UTF-8" />
+ </target>
+
+ <target name="executar-os-testes" depends="compilar">
+ <junit haltonfailure="true">
+ <classpath location="classes-teste/" />
+ <classpath refid="tests.classpath" />
+ <batchtest todir="${artifacts.dir}/reports">
+ <fileset dir="classes-teste/" >
+ <include name="**/*Test.class" />
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="gerar-jar" depends="executar-os-testes">
+ <jar destfile="pm-75-leiloes.jar" basedir="classes/" />
+ </target>
+</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
+package br.com.caelum.leilao.dominio;
+
+public class Lance {
+
+ private Usuario usuario;
+ private double valor;
+
+ public Lance(Usuario usuario, double valor) {
+ this.usuario = usuario;
+ this.valor = valor;
+ }
+
+ public Usuario getUsuario() {
+ return usuario;
+ }
+
+ public double getValor() {
+ return valor;
+ }
+
+
+
+}
@@ -0,0 +1,31 @@
+package br.com.caelum.leilao.dominio;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class Leilao {
+
+ private String descricao;
+ private List<Lance> lances;
+
+ public Leilao(String descricao) {
+ this.descricao = descricao;
+ this.lances = new ArrayList<Lance>();
+ }
+
+ public void propoe(Lance lance) {
+ lances.add(lance);
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+
+ public List<Lance> getLances() {
+ return Collections.unmodifiableList(lances);
+ }
+
+
+
+}
@@ -0,0 +1,27 @@
+package br.com.caelum.leilao.dominio;
+
+public class Usuario {
+
+ private int id;
+ private String nome;
+
+ public Usuario(String nome) {
+ this(0, nome);
+ }
+
+ public Usuario(int id, String nome) {
+ this.id = id;
+ this.nome = nome;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+
+
+}
@@ -0,0 +1,35 @@
+package br.com.caelum.leilao.servico;
+
+import br.com.caelum.leilao.dominio.Lance;
+import br.com.caelum.leilao.dominio.Leilao;
+
+class Avaliador {
+
+ private double maiorDeTodos = Double.NEGATIVE_INFINITY;
+ private double menorDeTodos = Double.POSITIVE_INFINITY;
+ private double media = 0;
+
+ public void avalia(Leilao leilao) {
+ double total = 0;
+ for (Lance lance : leilao.getLances()) {
+ if (lance.getValor() > maiorDeTodos)
+ maiorDeTodos = lance.getValor();
+ if (lance.getValor() < menorDeTodos)
+ menorDeTodos = lance.getValor();
+ total += lance.getValor();
+ }
+ media = total / leilao.getLances().size();
+ }
+
+ public double getMaiorLance() {
+ return maiorDeTodos;
+ }
+
+ public double getMenorLance() {
+ return menorDeTodos;
+ }
+
+ public double getMedia() {
+ return media;
+ }
+}
@@ -0,0 +1,55 @@
+package br.com.caelum.leilao.servico;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import br.com.caelum.leilao.dominio.Lance;
+import br.com.caelum.leilao.dominio.Leilao;
+import br.com.caelum.leilao.dominio.Usuario;
+
+public class AvaliadorTest {
+
+ @Test
+ public void deveEntenderLancesEmOrdemCrescente() {
+ // cenario: 3 lances em ordem crescente
+ Usuario joao = new Usuario("Joao");
+ Usuario jose = new Usuario("José");
+ Usuario maria = new Usuario("Maria");
+
+ Leilao leilao = new Leilao("Playstation 3 Novo");
+
+ leilao.propoe(new Lance(maria,250.0));
+ leilao.propoe(new Lance(joao,300.0));
+ leilao.propoe(new Lance(jose,400.0));
+
+ // executando a acao
+ Avaliador leiloeiro = new Avaliador();
+ leiloeiro.avalia(leilao);
+
+ // comparando a saida com o esperado
+ double maiorEsperado = 400;
+ double menorEsperado = 250;
+
+ Assert.assertEquals(maiorEsperado, leiloeiro.getMaiorLance(), 0.0001);
+ Assert.assertEquals(menorEsperado, leiloeiro.getMenorLance(), 0.0001);
+ }
+
+ @Test
+ public void deveCalcularAMedia() {
+ Usuario joao = new Usuario("Joao");
+ Usuario jose = new Usuario("José");
+ Usuario maria = new Usuario("Maria");
+
+ Leilao leilao = new Leilao("Playstation 3 Novo");
+
+ leilao.propoe(new Lance(maria,300.0));
+ leilao.propoe(new Lance(joao,400.0));
+ leilao.propoe(new Lance(jose,500.0));
+
+ Avaliador leiloeiro = new Avaliador();
+ leiloeiro.avalia(leilao);
+
+ Assert.assertEquals(400, leiloeiro.getMedia(), 0.0001);
+ }
+
+}

0 comments on commit 1ddc13f

Please sign in to comment.