Commit 0749568c authored by Fernandez Teodoro's avatar Fernandez Teodoro

Entrega Taller Refactoring

parent de7ac3db
<<<<<<< HEAD
### Laboratorio de Programación y lenguajes 2021
=======
### Laboratorio de Programación y lenguajes
>>>>>>> ad4a3b263ac940265ca637bed056c66f9dc56bf1
### Taller Refactoring
-Para aplicar DIP y LSP en ambos casos tuve que crear una clase de la cual extiendan sus "especializaciones" en las cuales esas extensiones tenian que definir el funcionamiento de la misma (aplicacion de LSP) y crear una Factoria para instanciar los objetos a traves de ella ( DIP )
......
<<<<<<< HEAD
const { setWorldConstructor } = require("@cucumber/cucumber");
module.exports = createStatementData = function (invoice, plays) {
module.exports = createStatementData = function createStatementData(
invoice,
plays
) {
let statementData = {};
statementData.customer = invoice.customer;
statementData.performances = invoice.performances.map(enrichPerformance);
let statementData = {};
statementData.customer = invoice.customer;
statementData.performances = invoice.performances.map(enrichPerformance);
statementData.totalAmount = totalAmount(statementData.performances);
statementData.totalVolumenCredits = totalVolumenCredits(
statementData.performances
);
statementData.totalAmount = totalAmount(statementData.performances);
statementData.totalVolumenCredits = totalVolumenCredits(statementData.performances);
return statementData;
return statementData;
function enrichPerformance(aPerformance) {
// const calculator = new PerformanceCalculator(aPerformance, playFor(aPerformance));
const calculator = createPerformanceCalculator(aPerformance, playFor(aPerformance));
const result = Object.assign({}, aPerformance);
result.play = playFor(result);
result.amount = calculator.amount;
result.volumeCredits = calculator.volumeCredits;
return result;
}
function enrichPerformance(aPerformance) {
const calculator = createPerformanceCalculator(
aPerformance,
playFor(aPerformance)
);
const result = Object.assign({}, aPerformance);
result.play = playFor(result);
result.amount = calculator.amount;
result.volumeCredits = calculator.volumeCredits;
return result;
}
function playFor(aPerformance) {
return plays[aPerformance.playID];
}
function playFor(aPerformace) {
return plays[aPerformace.playID];
}
function totalAmount(somePerformances) {
return somePerformances.reduce((prev, aPerformance) => prev + aPerformance.amount, 0);
}
function totalAmount(somePerformances) {
return somePerformances.reduce(
(prev, aPerformance) => prev + aPerformance.amount,
0
);
}
function totalVolumenCredits(somePerformances) {
return somePerformances.reduce((prev, aPerformance) => prev + aPerformance.volumeCredits, 0);
}
function totalVolumenCredits(somePerformances) {
return somePerformances.reduce(
(prev, aPerformance) => prev + aPerformance.volumeCredits,
0
);
}
function createPerformanceCalculator(aPerformance, aPlay) {
switch (aPlay.type) {
case "tragedy":
return new TragedyCalculator(aPerformance, aPlay);
case "comedy":
return new ComedyCalculator(aPerformance, aPlay);
default:
throw new Error(`tipo desconocido: ${this.play.type}`);
}
}
};
class PerformanceCalculator {
constructor(aPerformance, aPlay) {
this.performance = aPerformance;
this.play = aPlay;
}
function createPerformanceCalculator(aPerformance, aPlay) {
switch (aPlay.type) {
case "tragedy":
return new TragedyCalculator(aPerformance, aPlay);
case "comedy":
return new ComedyCalculator(aPerformance, aPlay);
default:
throw new Error(`unknown type: ${this.play.type}`);
}
}
return statementData;
}
get amount() {
throw new Error(`responsabilidad de subclase`);
}
class PerformanceCalculator {
constructor(aPerformance, aPlay) {
this.performance = aPerformance;
this.play = aPlay;
}
get volumeCredits() {
throw new Error(`responsabilidad de subclase`);
}
get amount() {
throw new Error('amount not supported in PerfomanceCalculator');
}
get volumeCredits() {
throw new Error('volumeCredits not supported in PerfomanceCalculator');
}
}
class TragedyCalculator extends PerformanceCalculator {
get amount() {
let result = 40000;
if (this.performance.audience > 30) {
result += 1000 * (this.performance.audience - 30);
}
return result;
}
get amount() {
let result = 40000;
if (this.performance.audience > 30) {
result += 1000 * (this.performance.audience - 30);
}
return result;
}
get volumeCredits() {
return volumeCreditsComposer(this.performance.audience);
}
get volumeCredits() {
return volumeCreditsComposer(this.performance.audience);
}
}
class ComedyCalculator extends PerformanceCalculator {
get amount() {
let result = 30000;
if (this.performance.audience > 20) {
result += 10000 + 500 * (this.performance.audience - 20);
}
result += 300 * this.performance.audience;
return result;
}
get amount() {
let result = 30000;
if (this.performance.audience > 20) {
result += 10000 + 500 * (this.performance.audience - 20);
}
result += 300 * this.performance.audience;
return result;
}
get volumeCredits() {
return (
volumeCreditsComposer(this.performance.audience) +
Math.floor(this.performance.audience / 5)
);
}
get volumeCredits() {
return volumeCreditsComposer(this.performance.audience) + Math.floor(this.performance.audience / 5);
}
}
function volumeCreditsComposer(aAudience) {
return Math.max(aAudience - 30, 0);
}
=======
module.exports = createStatementData = function (invoice, plays) {
const result = {};
result.customer = invoice.customer;
result.performances = invoice.performances.map(enrichPerformance);
result.totalAmount = totalAmount(result.performances);
result.totalVolumeCredits = totalVolumeCredits(result.performances);
return result;
function enrichPerformance(aPerformance) {
const calculator = createPerformanceCalculator(aPerformance, playFor(aPerformance));
const result = Object.assign({}, calculator.performance);
result.play = calculator.play;
result.amount = calculator.amount;
result.volumeCredits = calculator.volumeCredits;
return result;
}
function playFor(aPerformance) {
return plays[aPerformance.playID];
}
function totalAmount(somePerformances) {
return somePerformances.reduce(
(result, aPerformance) => result + aPerformance.amount, 0
);
}
function totalVolumeCredits(somePerformances) {
return somePerformances.reduce(
(result, aPerformance) => result + aPerformance.volumeCredits, 0
);
}
}
function createPerformanceCalculator(aPerformance, aPlay) {
switch (aPlay.type) {
case "tragedy": return new TragedyCalculator(aPerformance, aPlay);
case "comedy": return new ComedyCalculator(aPerformance, aPlay);
default:
throw new Error(`unknown type: ${this.play.type}`);
}
}
class PerformanceCalculator {
constructor(aPerformance, aPlay) {
this.performance = aPerformance;
this.play = aPlay;
}
get amount() {
throw new Error(`subclass responsability`);
}
get volumeCredits() {
return Math.max(this.performance.audience - 30, 0);
}
}
class TragedyCalculator extends PerformanceCalculator {
get amount() {
result = 40000;
if (this.performance.audience > 30) {
result += 1000 * (this.performance.audience - 30);
}
return result;
}
}
class ComedyCalculator extends PerformanceCalculator {
get amount() {
result = 30000;
if (this.performance.audience > 20) {
result += 10000 + 500 * (this.performance.audience - 20);
}
result += 300 * this.performance.audience;
return result;
}
get volumeCredits() {
return super.volumeCredits + Math.floor(this.performance.audience / 5);
}
}
>>>>>>> ad4a3b263ac940265ca637bed056c66f9dc56bf1
function volumeCreditsComposer(aAudience){
return Math.max(aAudience - 30, 0);
}
\ No newline at end of file
<<<<<<< HEAD
module.exports = {
default: `--format-options '{"snippetInterface": "synchronous"}'--publish-quiet`
default: `--format-options '{"snippetInterface": "synchronous"}' --publish-quiet`
}
=======
module.exports = {
default: `--format-options '{"snippetInterface": "synchronous"}'`
}
>>>>>>> ad4a3b263ac940265ca637bed056c66f9dc56bf1
<<<<<<< HEAD
# language: es
Característica: Imprimir la factura de una compañía teatral
......@@ -42,8 +41,8 @@ Escenario: imprimr la factura de BigCo en texto plano
}
}
"""
Cuando mando a imprimir el borderau en texto plano con dolares
Entonces debería imprimir el borderau en texto plano con dolares
Cuando mando a imprimir el borderau en texto con dolares
Entonces debería imprimir el borderau en texto con dolares
"""
Statement for BigCo
Hamlet: $650.00 (55 seats)
......@@ -52,14 +51,14 @@ Escenario: imprimr la factura de BigCo en texto plano
Amount owed is $1,730.00
You earned 47 credits
"""
Cuando mando a imprimir el borderau en texto plano con pesos argentinos
Entonces debería imprimir el borderau en texto plano con pesos argentinos
Cuando mando a imprimir el borderau en texto con pesos argentinos
Entonces debería imprimir el borderau en texto con pesos argentinos
"""
Statement for BigCo
Hamlet: $ 650,00 (55 seats)
As You Like It: $ 580,00 (35 seats)
Othello: $ 500,00 (40 seats)
Amount owed is $ 1.730,00
Hamlet: $650,00 (55 seats)
As You Like It: $580,00 (35 seats)
Othello: $500,00 (40 seats)
Amount owed is $1.730,00
You earned 47 credits
"""
......@@ -101,7 +100,7 @@ Escenario: imprimr la factura de BigCo en HTML
}
}
"""
Cuando mando a imprimir el borderau en HTML con dolares
Cuando mando a imprimir el borderau en HTML con dolares
Entonces debería imprimir el borderau en HTML con dolares
"""
<h1>Statement for BigCo</h1>
......@@ -114,225 +113,16 @@ Escenario: imprimr la factura de BigCo en HTML
<p>Amount owed is <em>$1,730.00</em></p>
<p>You earned <em>47</em> credits</p>
"""
Cuando mando a imprimir el borderau en HTML con pesos argentinos
Cuando mando a imprimir el borderau en HTML con pesos argentinos
Entonces debería imprimir el borderau en HTML con pesos argentinos
"""
<h1>Statement for BigCo</h1>
<table>
<tr><th>play</th><th>seats</th><th>cost</th></tr>
<tr><td>Hamlet</td><td>55</td><td>$ 650,00</td></tr>
<tr><td>As You Like It</td><td>35</td><td>$ 580,00</td></tr>
<tr><td>Othello</td><td>40</td><td>$ 500,00</td></tr>
<tr><td>Hamlet</td><td>55</td><td>$650,00</td></tr>
<tr><td>As You Like It</td><td>35</td><td>$580,00</td></tr>
<tr><td>Othello</td><td>40</td><td>$500,00</td></tr>
</table>
<p>Amount owed is <em>$ 1.730,00</em></p>
<p>Amount owed is <em>$1.730,00</em></p>
<p>You earned <em>47</em> credits</p>
"""
=======
# language: es
Característica: Imprimir la factura de una compañía teatral
Necesaria para liquidar el borderau
Escenario: imprimir la factura de BigCo en texto plano
Dado el listado de la facturación de espectáculos
"""
{
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 55
},
{
"playID": "as-like",
"audience": 35
},
{
"playID": "othello",
"audience": 40
}
]
}
"""
Y la lista de obras
"""
{
"hamlet": {
"name": "Hamlet",
"type": "tragedy"
},
"as-like": {
"name": "As You Like It",
"type": "comedy"
},
"othello": {
"name": "Othello",
"type": "tragedy"
}
}
"""
Cuando mando a imprimir el borderau
Entonces debería imprimir el borderau
"""
Statement for BigCo
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Amount owed is $1,730.00
You earned 47 credits
"""
Escenario: imprimir la factura de BigCo en HTML
Dado el listado de la facturación de espectáculos
"""
{
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 55
},
{
"playID": "as-like",
"audience": 35
},
{
"playID": "othello",
"audience": 40
}
]
}
"""
Y la lista de obras
"""
{
"hamlet": {
"name": "Hamlet",
"type": "tragedy"
},
"as-like": {
"name": "As You Like It",
"type": "comedy"
},
"othello": {
"name": "Othello",
"type": "tragedy"
}
}
"""
Cuando mando a imprimir el borderau en HTML
Entonces debería imprimir el borderau en HTML
"""
<h1>Statement for BigCo</h1>
<table>
<tr><th>play</th><th>seats</th><th>cost</th></tr>
<tr><td>Hamlet</td><td>55</td><td>$650.00</td></tr>
<tr><td>As You Like It</td><td>35</td><td>$580.00</td></tr>
<tr><td>Othello</td><td>40</td><td>$500.00</td></tr>
</table>
<p>Amount owed is <em>$1,730.00</em></p>
<p>You earned <em>47</em> credits</p>
"""
Escenario: imprimir la factura de BigCo en HTML con moneda ARS
Dado el listado de la facturación de espectáculos
"""
{
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 55
},
{
"playID": "as-like",
"audience": 35
},
{
"playID": "othello",
"audience": 40
}
]
}
"""
Y la lista de obras
"""
{
"hamlet": {
"name": "Hamlet",
"type": "tragedy"
},
"as-like": {
"name": "As You Like It",
"type": "comedy"
},
"othello": {
"name": "Othello",
"type": "tragedy"
}
}
"""
Cuando mando a imprimir el borderau en HTML con moneda ARS
Entonces debería imprimir el borderau en HTML con moneda ARS
"""
<h1>Statement for BigCo</h1>
<table>
<tr><th>play</th><th>seats</th><th>cost</th></tr>
<tr><td>Hamlet</td><td>55</td><td>ARS 650.00</td></tr>
<tr><td>As You Like It</td><td>35</td><td>ARS 580.00</td></tr>
<tr><td>Othello</td><td>40</td><td>ARS 500.00</td></tr>
</table>
<p>Amount owed is <em>ARS 1,730.00</em></p>
<p>You earned <em>47</em> credits</p>
"""
Escenario: imprimir la factura de BigCo en texto plano con moneda ARS
Dado el listado de la facturación de espectáculos
"""
{
"customer": "BigCo",
"performances": [
{
"playID": "hamlet",
"audience": 55
},
{
"playID": "as-like",
"audience": 35
},
{
"playID": "othello",
"audience": 40
}
]
}
"""
Y la lista de obras
"""
{
"hamlet": {
"name": "Hamlet",
"type": "tragedy"
},
"as-like": {
"name": "As You Like It",
"type": "comedy"
},
"othello": {
"name": "Othello",
"type": "tragedy"
}
}
"""
Cuando mando a imprimir el borderau en texto plano con moneda ARS
Entonces debería imprimir el borderau con moneda ARS
"""
Statement for BigCo
Hamlet: ARS 650.00 (55 seats)
As You Like It: ARS 580.00 (35 seats)
Othello: ARS 500.00 (40 seats)
Amount owed is ARS 1,730.00
You earned 47 credits
"""
>>>>>>> ad4a3b263ac940265ca637bed056c66f9dc56bf1
"""
\ No newline at end of file
const assert = require('assert');
const { Given, When, Then } = require('cucumber');
const print_the_bill = require('../../statement');
Given('el listado de la facturación de espectáculos', function (espectaculos) {
this.invoice = JSON.parse(espectaculos);
});
Given('la lista de obras', function (obras) {
this.play = JSON.parse(obras);
});
When('mando a imprimir el borderau en texto plano con dolares', function () {