Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución Ignacio González #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
17 changes: 17 additions & 0 deletions SOLUCION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Ignacio González Pozo - [email protected]

Fase A - Escenarios de prueba whatsapp

Herramientas: Gherkin

Ubicacion:
src/test/java/challenge.faseA


Fase B - Desarrollo Kata09: Back to the Checkout

Herramientas: Java - junit - Maven

Ubicacion:
src/java/challenge.faseB
src/test/java/challenge.faseB
76 changes: 76 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>challenge</groupId>
<artifactId>qachallenge</artifactId>
<version>1.0-SNAPSHOT</version>

<name>qachallenge</name>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
110 changes: 110 additions & 0 deletions src/main/java/challenge/faseB/CheckOut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package challenge.faseB;

import java.text.DecimalFormat;
import java.util.Map;
import java.util.TreeMap;

/**
* Contiene carro de compra y aplica descuentos de acuerdo a promociones actuales
*/

public class CheckOut {
//Items en carro de compras
private Map<String, Integer> checkedItems = new TreeMap<>();

//Valor total a pagar
private Double totalPrice = 0.0;

//Recibe promociones actuales
private Map<String, Promotion> promotionRules;

//Formatea a dos decimales
private DecimalFormat decimal = new DecimalFormat("#.##");

public CheckOut(Map promotionRules) {
this.promotionRules = promotionRules;
}

public Double getTotalPrice () {
return this.totalPrice;
}

/**
* Calcula total a pagar y aplica promociones
*/
public void totalCalculator () {
//Total sin descuentos
System.out.println("TOTAL: " + decimal.format(totalPrice));

//Aplica promociones y descuentos en caso de aplicar
applyPromotions();

System.out.println();
//Total con descuentos
System.out.println("TOTAL PRICE: " + decimal.format(totalPrice));
}
/**
* Añade los items al carro
*/
public void checkItem (String item) {
if(checkedItems.containsKey(item))
checkedItems.put(item, checkedItems.get(item) + 1);
else
{
checkedItems.put(item, 1);
}
//Total hasta al momento por cada item añadido, sin descuentos
totalPrice = totalPrice + promotionRules.get(item).getUnitPrice();
}
/**
* Aplica promociones al carro de compra
*/
private void applyPromotions() {
//Iteracion por items en carro de compras
for (Map.Entry<String, Integer> entry : checkedItems.entrySet()) {

//Verifica si item en carro de compras tiene promocion
if (promotionRules.containsKey(entry.getKey()) &&
promotionRules.get(entry.getKey()).getPromotionRequirement() != null) {

//Valida tipo promocion a aplicar, en caso de existir mas promociones
if (promotionRules.get(entry.getKey()).getPromotionType().equals("MOREFORLESS")) {
moreForLess(entry);
}
}
}
}
/**
* Aplica reglas de promocion MOREFORLESS
*/
private void moreForLess (Map.Entry<String, Integer> entry) {
//Verifica si cumple requisito de promocion
if (promotionRules.get(entry.getKey()).getPromotionRequirement() <= entry.getValue()) {

//Calcula valor sin promocion, cantidad del item * precio unitario
Double sumNoPromo = entry.getValue() * promotionRules.get(entry.getKey()).getUnitPrice();

//Cantidad veces se aplica valor promocion
Integer timesPromo = entry.getValue() / promotionRules.get(entry.getKey()).getPromotionRequirement();
//Cantidad items sin promocion
Integer itemsNoPromo = (entry.getValue() % promotionRules.get(entry.getKey()).getPromotionRequirement());

//Calcula valor total item aplicando promocion
Double sumPromo = (timesPromo * promotionRules.get(entry.getKey()).getPromotionPrice()) +
(itemsNoPromo * promotionRules.get(entry.getKey()).getUnitPrice());

//Calcula descuento aplicado al item, total sin promocion - total con promocion
Double discount = sumNoPromo - sumPromo;

System.out.println("MOREFORLESS Saved " + decimal.format(discount) + " on item " +entry.getKey());

applyDiscount(discount);
}
}
/**
* Aplica descuento al total a pagar
*/
public void applyDiscount (Double discount) {
totalPrice = totalPrice - discount;
}
}
36 changes: 36 additions & 0 deletions src/main/java/challenge/faseB/Promotion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package challenge.faseB;

/**
* Clase para asignacion de promociones a producto
* tipoPromocion, precioPromocion, requisitoPromocion
*/

public class Promotion {
private String promotionType;
private Double promotionPrice;
private Integer promotionRequirement;
private Double unitPrice;

public Promotion(String promotionType, Double promotionPrice, Integer promotionRequirement, Double unitPrice) {
this.promotionType = promotionType;
this.promotionPrice = promotionPrice;
this.promotionRequirement = promotionRequirement;
this.unitPrice = unitPrice;
}

public String getPromotionType(){
return this.promotionType;
}

public Integer getPromotionRequirement(){
return this.promotionRequirement;
}

public Double getPromotionPrice(){
return this.promotionPrice;
}

public Double getUnitPrice(){
return this.unitPrice;
}
}
31 changes: 31 additions & 0 deletions src/main/java/challenge/faseB/PromotionLibrary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package challenge.faseB;

import java.util.Map;
import java.util.TreeMap;

/**
* Contiene promociones actuales
* Item en Promocion, tipoPromocion, precioPromocion, requisitoPromocion
*
* Precios unitarios por item
* "A", 50
* "B", 30
* "C", 20
* "D", 15
*/

public class PromotionLibrary {

public static Map promotionIndex = new TreeMap<String, Promotion>();

static {
promotionIndex.put("A",
new Promotion("MOREFORLESS", 130.0,3, 50.0));
promotionIndex.put("B",
new Promotion("MOREFORLESS", 45.0,2, 30.0));
promotionIndex.put("C",
new Promotion("MOREFORLESS", null,null, 20.0));
promotionIndex.put("D",
new Promotion("MOREFORLESS", null,null, 15.0));
}
}
41 changes: 41 additions & 0 deletions src/main/java/challenge/faseB/Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package challenge.faseB;

/**
* Ignacio González Pozo - [email protected]
* Precios unitarios por item
* "A",50
* "B",30
* "C",20
* "D",15
*/
public class Runner
{
public static void main( String[] args )
{

CheckOut co = new CheckOut(PromotionLibrary.promotionIndex);

//Valores para posibles items: A - B - C - D
co.checkItem("A");
co.checkItem("A");
co.checkItem("A");
co.checkItem("D");
co.checkItem("C");
co.checkItem("D");
co.checkItem("A");
co.checkItem("A");
co.checkItem("B");
co.checkItem("B");
co.checkItem("A");
co.checkItem("A");
co.checkItem("A");
co.checkItem("D");
co.checkItem("C");
co.checkItem("D");
co.checkItem("A");
co.checkItem("A");
co.checkItem("B");
co.checkItem("B");
co.totalCalculator();
}
}
47 changes: 47 additions & 0 deletions src/test/java/challenge/faseA/enviar-documento.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Feature: Enviar documentos
Como usuario de la aplicación whatsapp de telefono Android
quiero adjuntar documentos a una conversacion
para compartir archivos que tengo en el telefono

#Given - Dado que
#When - Cuando
#Then - Entonces

Background:
Given me encuentro en la conversacion "chat xyz"

Scenario Outline: Adjuntar un documento a la conversacion
When se selecciona la opcion de adjuntar documento
And envio un <documento>
Then se muestra recuadro que indica nombre documento y progreso de envio
And al finalizar el envio permite descargar el documento

Examples: #documento: formato de documento a adjuntar
| documento |
| pdf |
| doc |
| rar |


Scenario Outline: Cancelar envio de documento a la conversacion
When se selecciona la opcion de adjuntar documento
And envio un <documento>
And presiona el progreso del envio para cancelarlo
Then el envio se cancela y permite en el mensaje volver a enviarlo

Examples: #documento: formato de documento a adjuntar
| documento |
| rar |


Scenario: Adjuntar mas de un documento a la conversacion
When se selecciona la opcion de adjuntar documento
And envio mas de un documento
Then se muestra recuadro que indica nombre y progreso del envio en cada uno
And al finalizar el envio permite descargar cada documento


Scenario: Adjuntar documento superior a 99MB
When se selecciona la opcion de adjuntar documento
And se envia un documento superior a 99MB
Then se cancela el envio con mensaje de error "mensaje"
Loading