diff --git a/challengeA/yoshifumi_sawada/.rspec b/challengeA/yoshifumi_sawada/.rspec new file mode 100644 index 000000000..c99d2e739 --- /dev/null +++ b/challengeA/yoshifumi_sawada/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/challengeA/yoshifumi_sawada/Gemfile b/challengeA/yoshifumi_sawada/Gemfile new file mode 100644 index 000000000..75b60910c --- /dev/null +++ b/challengeA/yoshifumi_sawada/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" +gem "rspec", ">= 3.0.0" +gem 'pry', '~> 0.13.1' \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/Gemfile.lock b/challengeA/yoshifumi_sawada/Gemfile.lock new file mode 100644 index 000000000..224b6b9d3 --- /dev/null +++ b/challengeA/yoshifumi_sawada/Gemfile.lock @@ -0,0 +1,32 @@ +GEM + remote: https://rubygems.org/ + specs: + coderay (1.1.3) + diff-lcs (1.4.4) + method_source (1.0.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + +PLATFORMS + ruby + +DEPENDENCIES + pry (~> 0.13.1) + rspec (>= 3.0.0) + +BUNDLED WITH + 2.1.4 diff --git a/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv new file mode 100644 index 000000000..35092f505 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/jxtg/basic_charge.csv @@ -0,0 +1,5 @@ +amp,basic_charge +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv new file mode 100644 index 000000000..77bea28a8 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/jxtg/usage_charge.csv @@ -0,0 +1,5 @@ +kwh_from,kwh_to,unit_price +0,120,19.88 +120,300,26.48 +300,600,25.08 +600,Float::INFINITY,26.15 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv new file mode 100644 index 000000000..76d887d02 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/loop/basic_charge.csv @@ -0,0 +1,8 @@ +amp,basic_charge +10,0 +15,0 +20,0 +30,0 +40,0 +50,0 +60,0 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv new file mode 100644 index 000000000..bb518b91a --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/loop/usage_charge.csv @@ -0,0 +1,2 @@ +kwh,unit_price +0,26.4 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/plans.csv b/challengeA/yoshifumi_sawada/csv/plans.csv new file mode 100644 index 000000000..43c837c53 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/plans.csv @@ -0,0 +1,5 @@ +provider_name,plan_name +東京電力エナジーパートナー,従量電灯B +Looopでんき,おうちプラン +東京ガス,ずっとも電気1 +JXTGでんき,従量電灯B たっぷりプラン \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv new file mode 100644 index 000000000..7794806e8 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/basic_charge.csv @@ -0,0 +1,8 @@ +amp,basic_charge +10,286 +15,429 +20,572 +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv new file mode 100644 index 000000000..0a2ef5685 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyo_energy_partner/usage_charge.csv @@ -0,0 +1,4 @@ +kwh_from,kwh_to,unit_price +0,120,19.88 +120,300,26.48 +300,Float::INFINITY,30.57 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv new file mode 100644 index 000000000..35092f505 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/basic_charge.csv @@ -0,0 +1,5 @@ +amp,basic_charge +30,858 +40,1144 +50,1430 +60,1716 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv new file mode 100644 index 000000000..d7d2ea290 --- /dev/null +++ b/challengeA/yoshifumi_sawada/csv/tokyogas/usage_charge.csv @@ -0,0 +1,4 @@ +kwh_from,kwh_to,unit_price +0,140,23.67 +140,350,23.88 +350,Float::INFINITY,26.41 \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/basic_charge.rb b/challengeA/yoshifumi_sawada/lib/basic_charge.rb new file mode 100644 index 000000000..6b4a21843 --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/basic_charge.rb @@ -0,0 +1,39 @@ +require "csv" +require "pry" + +class Basic_charge + def self.import(path) + if path[:path].include?("tokyo_energy_partner") + CSV.read("csv/tokyo_energy_partner/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i + } + end + + elsif path[:path].include?("loop") + CSV.read("csv/loop/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i + } + end + + elsif path[:path].include?("tokyogas") + CSV.read("csv/tokyogas/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i + } + end + + elsif path[:path].include?("jxtg") + CSV.read("csv/jxtg/basic_charge.csv", headers: true).map do |row| + { + amp: row["amp"].to_i, + basic_charge: row["basic_charge"].to_i + } + end + end +end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/plan.rb b/challengeA/yoshifumi_sawada/lib/plan.rb new file mode 100644 index 000000000..6e8b58f49 --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/plan.rb @@ -0,0 +1,14 @@ +require "csv" +require "pry" + +class Plan + def self.import(path) + # 全てを読込、配列を作成 + CSV.read("csv/plans.csv", headers: true).map do |row| + { + provider_name: row["provider_name"], + plan_name: row["plan_name"] + } + end + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/simulator.rb b/challengeA/yoshifumi_sawada/lib/simulator.rb new file mode 100644 index 000000000..a3bbcd65d --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/simulator.rb @@ -0,0 +1,109 @@ +require "pry" +require_relative "plan" +require_relative "basic_charge" +require_relative "usage_charge" + +class Simulator + + def initialize(amp,usage_per_month) + @amp = amp + @usage_per_month = usage_per_month + end + + def simulate + # 東京電力エナジーパートナー従量電灯Bの電気量料金のCSVデータをインポート + usage_datas = Usage_charge.import(path: "../csv/tokyo_energy_partner/usage_charge.csv") + # 東京電力エナジーパートナーの従量電灯Bの電気量料金 + usage_charge1 = calculate(usage_datas) + # 東京ガスのずっとも電気1の電気量料金の電気量料金テーブルのCSVデータをインポート + usage_datas3 = Usage_charge.import(path: "../csv/tokyogas/usage_charge.csv") + # 東京ガスのずっとも電気1の電気量料金 + usage_charge3 = calculate(usage_datas3) + + # JXTGでんき 従量電灯B たっぷりプランの電気量料金の電気量料金テーブルのCSVデータをインポート + usage_datas4 = Usage_charge.import(path: "../csv/jxtg/usage_charge.csv") + # 東京ガスのずっとも電気1の電気量料金 + usage_charge4 = calculate(usage_datas4) + + # Looopでんきのおうちプランの電気量料金テーブルのCSVデータをインポート + usage_datas2 = Usage_charge.import(path: "../csv/loop/usage_charge.csv") + # Looopでんきのおうちプランの電気量料金の単価 + usage_charge_data2 = usage_datas2.find { |data| data['kwh'] == 0.0 } + unit_price2 = usage_charge_data2["unit_price"] + + + # 基本料金テーブルのCSVデータをインポート + basic_charge_table = Basic_charge.import(path: "../csv/tokyo_energy_partner/basic_charge.csv") + basic_charge_table2 = Basic_charge.import(path: "../csv/loop/basic_charge.csv") + basic_charge_table3 = Basic_charge.import(path: "../csv/tokyogas/basic_charge.csv") + basic_charge_table4 = Basic_charge.import(path: "../csv/jxtg/basic_charge.csv") + + + # プロバイダと料金プラン名のCSVデータをインポート + plan_datas = Plan.import(path: "csv/plans.csv") + + # 該当プランに価格の計算結果のハッシュを追加 + plan_list = plan_datas.each do |data| + case + when data[:provider_name] == "東京電力エナジーパートナー" + charge_data = basic_charge_table.find { |data| data[:amp] == @amp } + data[:price]= (charge_data[:basic_charge] + usage_charge1).floor.to_s + + when data[:provider_name] == "Looopでんき" + charge_data2 = basic_charge_table2.find { |data| data[:amp] == @amp } + data[:price]= (charge_data2[:basic_charge] + @usage_per_month * unit_price2).floor.to_s + + when data[:provider_name] == "東京ガス" && [30,40,50,60].include?(@amp) + charge_data3 = basic_charge_table3.find { |data| data[:amp] == @amp } + data[:price]= (charge_data3[:basic_charge] + usage_charge3).floor.to_s + + when data[:provider_name] == "JXTGでんき" && [30,40,50,60].include?(@amp) + charge_data4 = basic_charge_table4.find { |data| data[:amp] == @amp } + data[:price]= (charge_data4[:basic_charge] + usage_charge4).floor.to_s + end + end + + # priceキーに値が入ってるプランのみを表示 + p output_array = plan_list.select{|plan| plan.has_key?(:price)} + end + + private + + # 段階別料金プランの計算 + def calculate(usage_datas) + usage_charge = 0 + usage_datas.each do |usage_data| + if usage_data['kwh_from'] < @usage_per_month && @usage_per_month <= usage_data['kwh_to'] + usage_charge = usage_charge + usage_data['unit_price'] * (@usage_per_month - usage_data['kwh_from']) + elsif usage_data['kwh_to'] < @usage_per_month + usage_charge = usage_charge + usage_data['unit_price'] * (usage_data['kwh_to'] - usage_data['kwh_from']) + end + end + return usage_charge + end +end + +# #****************実行部分*************************************************************** + + +# 契約アンペアを入力して頂く +while true +print "契約アンペアを入力して下さい > " + amp = gets.to_i + break if [10,15,20,30,40,50,60].include?(amp) + puts "10,15,20,30,40,50,60のいずれかを入力して下さい" +end + +# 1ヶ月あたりの使用量を入力して頂く +while true +print "1ヶ月あたりの使用量を入力して下さい > " + usage_per_month = gets.to_i + break if usage_per_month >= 0 + puts "0以上の値を入力して下さい" +end + +# 入力値を引数にSimulatorクラスのインスタンスを生成 +simulator = Simulator.new(amp,usage_per_month) + +# インスタンスに対してsimulateメソッド(計算メソッド)を実行して出力結果を表示 +simulator.simulate \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/lib/usage_charge.rb b/challengeA/yoshifumi_sawada/lib/usage_charge.rb new file mode 100644 index 000000000..3648bc68a --- /dev/null +++ b/challengeA/yoshifumi_sawada/lib/usage_charge.rb @@ -0,0 +1,62 @@ +require "csv" +require "pry" +class Usage_charge + def self.import(path) + if path[:path].include?("tokyo_energy_partner") + list = [] + CSV.foreach("csv/tokyo_energy_partner/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } + end + return list + + elsif path[:path].include?("loop") + list = [] + CSV.foreach("csv/loop/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } + end + return list + + elsif path[:path].include?("tokyogas") + list = [] + CSV.foreach("csv/tokyogas/usage_charge.csv", headers: true) do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } + end + return list + + elsif path[:path].include?("jxtg") + list = [] + CSV.read("csv/jxtg/usage_charge.csv", headers: true).map do |row| + list << row.to_h.transform_values{|v| + case v + when "Float::INFINITY" + Float::INFINITY + else + v.to_f + end + } + end + return list + end + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/spec/simulator_spec.rb b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb new file mode 100644 index 000000000..7890fecfb --- /dev/null +++ b/challengeA/yoshifumi_sawada/spec/simulator_spec.rb @@ -0,0 +1,186 @@ +require_relative '../lib/simulator.rb' + +RSpec.describe Simulator do + describe "プラン名と料金を含む配列数と段階別の計算結果" do + context "20Aの場合" do + it "20A/120kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 120) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2957"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3168"} + ) + end + it "20A/121kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 121) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"2984"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3194"} + ) + end + it "20A/300kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7724"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"} + ) + end + it "20A/301kWhの場合、配列数2つ" do + simulator = Simulator.new(20, 301) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"7754"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"} + ) + end + end + + context "30Aの場合" do + it "30A/140kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 140) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3773"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4171"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3773"} + ) + end + it "30A/141kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 141) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"3799"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3722"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4195"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"3799"} + ) + end + it "30A/300kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8010"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"7992"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8010"} + ) + end + it "30A/301kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 301) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8040"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8016"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8035"} + ) + end + it "30A/350kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 350) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9538"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9186"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9264"} + ) + end + it "30A/351kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 351) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9569"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9266"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9213"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9289"} + ) + end + it "30A/600kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 600) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17181"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15840"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"15789"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15534"} + ) + end + it "30A/601kWhの場合、配列数4つ" do + simulator = Simulator.new(30, 601) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17211"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15866"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"15815"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15560"} + ) + end + end + + context "40Aの場合" do + it "40A/140kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 140) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"4059"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3696"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4457"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"4059"} + ) + end + it "40A/141kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 141) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"4085"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"3722"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"4481"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"4085"} + ) + end + it "40A/300kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 300) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8296"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7920"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8278"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8296"} + ) + end + it "40A/301kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 301) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"8326"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"7946"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"8302"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"8321"} + ) + end + it "40A/350kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 350) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9824"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9240"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9472"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9550"} + ) + end + it "40A/351kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 351) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"9855"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"9266"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"9499"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"9575"} + ) + end + it "40A/600kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 600) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17467"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15840"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"16075"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15820"} + ) + end + it "40A/601kWhの場合、配列数4つ" do + simulator = Simulator.new(40, 601) + expect(simulator.simulate).to contain_exactly( + {:provider_name=>"東京電力エナジーパートナー", :plan_name=>"従量電灯B", :price=>"17497"}, + {:provider_name=>"Looopでんき", :plan_name=>"おうちプラン", :price=>"15866"}, + {:provider_name=>"東京ガス", :plan_name=>"ずっとも電気1", :price=>"16101"}, + {:provider_name=>"JXTGでんき", :plan_name=>"従量電灯B たっぷりプラン", :price=>"15846"} + ) + end + end + end +end \ No newline at end of file diff --git a/challengeA/yoshifumi_sawada/spec/spec_helper.rb b/challengeA/yoshifumi_sawada/spec/spec_helper.rb new file mode 100644 index 000000000..251aa5106 --- /dev/null +++ b/challengeA/yoshifumi_sawada/spec/spec_helper.rb @@ -0,0 +1,100 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end