-
Notifications
You must be signed in to change notification settings - Fork 54
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
Controle adicional no limite de dimensões #20
base: master
Are you sure you want to change the base?
Changes from all commits
9e582b3
1e89190
b6a3a06
19faffd
720f4d0
197c4d0
33b744e
b593647
9162ebb
5456697
b3d201a
ad9afa4
887e47b
eec967e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,12 @@ class Pacote | |
:altura => 2.0 | ||
} | ||
|
||
MAX_DIMENSIONS = { | ||
:comprimento => 105.0, | ||
:largura => 105.0, | ||
:altura => 105.0 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Você pode usar somente uma variável já que o limite máximo é o mesmo para todas as dimensões. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pensei em fazer isso, mas deixei de faze-lo por que achei que ficaria mais claro separa-las. Vou fazer uma só, tem preferência de nome? (pensei em There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
def initialize(itens = nil) | ||
@peso = @comprimento = @largura = @altura = @volume = 0.0 | ||
@itens = [] | ||
|
@@ -48,8 +54,9 @@ def calcular_medidas(item) | |
@largura = item.largura | ||
@altura = item.altura | ||
else | ||
dimensao = @volume.to_f**(1.0/3) | ||
@comprimento = @largura = @altura = dimensao | ||
@comprimento = comprimento_itens | ||
@largura = largura_itens | ||
@altura = altura_itens | ||
end | ||
|
||
min_dimension_values | ||
|
@@ -64,6 +71,29 @@ def min_dimension_values() | |
def min(value, minimum) | ||
(value < minimum) ? minimum : value | ||
end | ||
|
||
def max(value, maximum) | ||
(value >= maximum) ? value : maximum | ||
end | ||
|
||
def dimensao | ||
@volume.to_f**(1.0/3) | ||
end | ||
|
||
def comprimento_itens | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um nome mais adequado para esse método seria |
||
max = @itens.map(&:comprimento).max | ||
max >= MAX_DIMENSIONS[:comprimento] ? max : dimensao | ||
end | ||
|
||
def largura_itens | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um nome mais adequado para esse método seria |
||
max = @itens.map(&:largura).max | ||
max >= MAX_DIMENSIONS[:largura] ? max : dimensao | ||
end | ||
|
||
def altura_itens | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um nome mais adequado para esse método seria |
||
max = @itens.map(&:altura).max | ||
max >= MAX_DIMENSIONS[:altura] ? max : dimensao | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# encoding: UTF-8 | ||
module Correios | ||
module Frete | ||
VERSION = "1.9.4" | ||
VERSION = "1.9.5" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Atualização de versão é feita somente no branch master. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,13 @@ | |
|
||
@pacote.adicionar_item(@item1) | ||
@pacote.adicionar_item(@item2) | ||
|
||
@exceeded_dimensions = Correios::Frete::PacoteItem.new( | ||
:altura => Correios::Frete::Pacote::MAX_DIMENSIONS[:altura] + 1, | ||
:largura => Correios::Frete::Pacote::MAX_DIMENSIONS[:largura] + 1, | ||
:comprimento => Correios::Frete::Pacote::MAX_DIMENSIONS[:comprimento] + 1, | ||
:peso => 1.0 | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Os valores excedidos de altura, largura e comprimento são iguais (106). Não há necessidade de se criar uma instância de There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verdade cara. Comecei pensando em criar um item para adiciona-lo no pacote, mas depois mudei a abordagem e acabou ficando ali por nada. Valeu por chamar a atenção p isso. |
||
end | ||
|
||
it "calculates package weight" do | ||
|
@@ -183,6 +190,81 @@ | |
expect(@pacote.altura).to eq(2) | ||
end | ||
end | ||
|
||
context "with at least one item dimension greater than maximum" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Na descrição do contexto está especificado "ao menos uma dimensão do item é maior que o máximo", mas os testes foram feitos com 3 itens de dimensão com tamanho excedido. Talvez seria melhor testar cada dimensão separada. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boa idéia :) |
||
before :each do | ||
over_lengthened = Correios::Frete::PacoteItem.new(:peso => 0.3, :largura => 1, :altura => 1, | ||
:comprimento => @exceeded_dimensions.comprimento) | ||
|
||
too_wide = Correios::Frete::PacoteItem.new(:peso => 0.3, :comprimento => 3, :altura => 1, | ||
:largura => @exceeded_dimensions.largura) | ||
|
||
over_heightened = Correios::Frete::PacoteItem.new(:peso => 0.3, :comprimento => 3, :largura => 1, | ||
:altura => @exceeded_dimensions.altura) | ||
|
||
@pacote = Correios::Frete::Pacote.new | ||
@pacote.adicionar_item(over_lengthened) | ||
@pacote.adicionar_item(too_wide) | ||
@pacote.adicionar_item(over_heightened) | ||
end | ||
|
||
it "shows biggest length value" do | ||
expect(@pacote.comprimento).to eq(@exceeded_dimensions.comprimento) | ||
end | ||
|
||
it "shows biggest width value" do | ||
expect(@pacote.largura).to eq(@exceeded_dimensions.largura) | ||
end | ||
|
||
it "shows biggest height value" do | ||
expect(@pacote.altura).to eq(@exceeded_dimensions.altura) | ||
end | ||
end | ||
|
||
context "over lengthed items with zero widht and height" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo. |
||
before :each do | ||
over_lengthened = Correios::Frete::PacoteItem.new(:peso => 0.3, :largura => 0, :altura => 0, | ||
:comprimento => @exceeded_dimensions.comprimento) | ||
|
||
@pacote = Correios::Frete::Pacote.new | ||
2.times{@pacote.adicionar_item(over_lengthened)} | ||
end | ||
|
||
it "does not get length information from minimum dimensions" do | ||
expect(@pacote.items.size).to eq(2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não há necessidade dessa expectativa. Ela está verificando se o cenário de testes foi montado corretamente. |
||
expect(@pacote.comprimento).to_not eq(Correios::Frete::Pacote::MIN_DIMENSIONS[:comprimento]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Foi colocada a expectativa negativa, mas não há nenhuma expectativa positiva. Sempre que se cria uma expectativa negativa em um teste, ela deve vir acompanhada de uma expectativa do valor que se espera obter. Nesse teste, se There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nossa, ótima dica! Muito bem lembrado, vou melhorar esse teste também. |
||
end | ||
end | ||
|
||
context "over widthed items with zero length and height" do | ||
before :each do | ||
too_wide = Correios::Frete::PacoteItem.new(:peso => 0.3, :comprimento => 0, :altura => 0, | ||
:largura => @exceeded_dimensions.largura) | ||
|
||
@pacote = Correios::Frete::Pacote.new | ||
2.times{@pacote.adicionar_item(too_wide)} | ||
end | ||
|
||
it "does not get width information from minimum dimensions" do | ||
expect(@pacote.items.size).to eq(2) | ||
expect(@pacote.largura).to_not eq(Correios::Frete::Pacote::MIN_DIMENSIONS[:largura]) | ||
end | ||
end | ||
|
||
context "over heighted items with zero widht and length" do | ||
before :each do | ||
over_heightened = Correios::Frete::PacoteItem.new(:peso => 0.3, :comprimento => 0, :largura => 0, | ||
:altura => @exceeded_dimensions.altura) | ||
|
||
@pacote = Correios::Frete::Pacote.new | ||
2.times{@pacote.adicionar_item(over_heightened)} | ||
end | ||
|
||
it "does not get height information from minimum dimensions" do | ||
expect(@pacote.items.size).to eq(2) | ||
expect(@pacote.altura).to_not eq(Correios::Frete::Pacote::MIN_DIMENSIONS[:altura]) | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Atualização de versão é feita somente no branch master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certo, me ficou uma dúvida: posso arrancar o texto numa boa? Você se encarrega de escrever outro texto para a mensagem de changelog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sim.