Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adicionado diretório ruby

  • Loading branch information...
commit 14f78b9a5e3bb26805ea5ed8975de209e1b40ee3 1 parent 4d64475
@jtadeulopes jtadeulopes authored
View
17 ruby/.gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
View
2  ruby/.rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
22 ruby/calc.rb
@@ -0,0 +1,22 @@
+# encoding: utf-8
+
+# Classe para efetuar calculos matematicos
+#
+class Calculadora
+
+ # Soma dois números
+ #
+ # Exemplo:
+ # calc = Calculadora.new
+ # calc.somar(2, 2)
+ # => 4
+ #
+ def somar(*args)
+ raise "Informe números" if args.any? {|n| !n.instance_of?(Fixnum)}
+ args.reduce(:+)
+ end
+
+ def subtrair(*args)
+ args.reduce(:-)
+ end
+end
View
49 ruby/spec/calc_spec.rb
@@ -0,0 +1,49 @@
+# encoding: utf-8
+
+require 'spec_helper'
+require './calc'
+
+describe Calculadora do
+
+ let(:calc) { Calculadora.new }
+
+ context "somando" do
+ it "deve somar dois números" do
+ calc.somar(2, 3).should == 5
+ end
+
+ it "deve somar tres números" do
+ calc.somar(2, 3, 5).should == 10
+ end
+
+ it "deve somar varios números" do
+ calc.somar(1, 2, 3, 4, 5).should == 15
+ end
+ end
+
+ context "subtraindo" do
+ it "deve subtrair dois numeros" do
+ calc.subtrair(10, 5).should == 5
+ end
+
+ it "deve subtrair varios numeros" do
+ calc.subtrair(10, 5, 3).should == 2
+ end
+ end
+
+ context "multiplicando" do
+ it "deve multiplicar dois numeros" do
+ calc.multiplicar(5, 5).should == 25
+ end
+
+ # escrever outros testes
+ end
+
+ context "dividindo" do
+ it "deve dividir dois numeros" do
+ calc.multiplicar(10, 5).should == 2
+ end
+
+ # escrever outros testes
+ end
+end
View
15 ruby/spec/spec_helper.rb
@@ -0,0 +1,15 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+
+require 'simplecov'
+SimpleCov.start
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
Please sign in to comment.
Something went wrong with that request. Please try again.