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

Primeiro commit teste #58

Open
wants to merge 2 commits 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
11 changes: 11 additions & 0 deletions Ajuste.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Funcionalidade: Ajuste

Possibilita para o usuário a opção de configurar sua conta do modo de que preferir.

Contexto: Dado que esteja logado no Whatsapp

Cenário: Trocar foto do perfil
Dado que esteja em edição de perfil dentro de ajustes
Quando alterar minha foto de perfil
Então a nova foto estará disponível para os contatos

14 changes: 14 additions & 0 deletions Conversa.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Funcionalidade: Conversa

Possibilita para o usuário a interação com outras pessoas.

Contexto: Dado que esteja logado no Whatsapp

Cenário: Iniciar uma nova conversa
Quando enviar uma mensagem a um novo contato
Então a mensagem aparecerá no chat

Cenário: Excluir conversa já iniciada
Dado que possua uma conversa iniciada
Quando excluir a conversa após ter selecionado uma
Então a conversa não deve mais aparecer
77 changes: 77 additions & 0 deletions codeKata/checkout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
class Discount
def initialize(value, quantity)
@value = value
@quantity = quantity
end

def calculate_for(quantity)
(quantity / @quantity).floor * @value
end
end

class PricePolicy
def initialize(starts_at, *discounts)
@starts_at = starts_at
@discounts = discounts
end

def price(quantity)
quantity * @starts_at - discount_for(quantity)
end

def discount_for(quantity)
@discounts.inject(0) do |mem, discount|
mem discount.calculate_for(quantity)
end
end
end

# Declare your products and discount rule
RULES = {
# Example of 'A' product, '50' base price, '20' is the discount provided when '3' products are buyed
'A' => PricePolicy.new(50, Discount.new(20, 3)),
'B' => PricePolicy.new(30, Discount.new(15, 2)),
# Notice the product can have a discount or not
'C' => PricePolicy.new(20),
'D' => PricePolicy.new(15),
}

class Checkout
def initialize(rules)
@rules = rules
@items = Hash.new
end

def scan(item)
@items[item] ||= 0
@items[item] = 1
end

def total
@items.inject(0) do |mem, (item, quantity)|
mem price(item, quantity)
end

end

def rule(item)
@rules[item]
end

def price(item, quantity)
if rule(item)
rule(item).price(quantity)
else
raise "Invalid '#{item}'"
end
end
private :rule, :price
end

class Test
def price(goods)
co = Checkout.new(RULES)
goods.split(//).each { |item| co.scan(item) }
co.total
end
end
82 changes: 82 additions & 0 deletions codeKata/teste.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

require "rspec"
require "C:/Users/julia.kawata/Desktop/DesafioJúlia/codeKata/checkout.rb"

describe "CheckoutItems" do
it "Assert - A" do
calc = Test.new()
price_item = calc.price("A")
expect(price_item).to eq(50)
end

it "Assert - AB" do
calc = Test.new()
price_item = calc.price("AB")
expect(price_item).to eq(80)
end

it "Assert - CDBA" do
calc = Test.new()
price_item = calc.price("CDBA")
expect(price_item).to eq(115)
end

it "Assert - AA" do
calc = Test.new()
price_item = calc.price("AA")
expect(price_item).to eq(100)
end

it "Assert - AAA" do
calc = Test.new()
price_item = calc.price("AAA")
expect(price_item).to eq(130)
end

it "Assert - AAAA" do
calc = Test.new()
price_item = calc.price("AAAA")
expect(price_item).to eq(180)
end

it "Assert - AAAAA" do
calc = Test.new()
price_item = calc.price("AAAAA")
expect(price_item).to eq(230)
end

it "Assert - AAAAAA" do
calc = Test.new()
price_item = calc.price("AAAAAA")
expect(price_item).to eq(260)
end

it "Assert - AAAB" do
calc = Test.new()
price_item = calc.price("AAAB")
expect(price_item).to eq(160)
end

it "Assert - AAABB" do
calc = Test.new()
price_item = calc.price("AAABB")
expect(price_item).to eq(175)
end

it "Assert - AAABBD" do
calc = Test.new()
price_item = calc.price("AAABBD")
expect(price_item).to eq(190)
end

it "Assert - DABABA" do
calc = Test.new()
price_item = calc.price("DABABA")
expect(price_item).to eq(190)
end

end