Skip to content

電気料金シミュレーションサービスを実装#11

Merged
en-Barry merged 6 commits into
developfrom
feature/2605/en-Barry/electricity-bill-simulator
May 12, 2026
Merged

電気料金シミュレーションサービスを実装#11
en-Barry merged 6 commits into
developfrom
feature/2605/en-Barry/electricity-bill-simulator

Conversation

@en-Barry
Copy link
Copy Markdown
Owner

@en-Barry en-Barry commented May 6, 2026

要約

Issue #6ElectricityBillSimulator.call(ampere:, kwh:) の TDD 実装)を解決する。

  • 全プランの料金計算・価格昇順ソート・戻り値整形を 1 クラスで実装
  • テストを先に書いてから実装する TDD サイクルで進めた

Closes #6

実装してみて発生した追加判断

  • sort_by の不安定性に対応: Ruby の sort_by は不安定ソートのため、同価格のプランが floor 後に一致した場合に順序が非決定的になる。[price, provider_id, plan_id] の 3 段 tiebreaker で決定的な並び順を保証した
  • Float を明示的に弾く: Integer() は Float(例: 30.0)を黙って切り捨てるため、事前チェックで Float 型を ArgumentError にした。「小数を整数として扱う」より「弾く」を選んだのは、呼び出し元(コントローラ)でリクエスト層の検証を済ませている前提のため

テストケース一覧

spec/services/electricity_bill_simulator_spec.rb(17 examples)

カテゴリ ケース ampere kwh 期待
基本料金あり + 段階制(従量電灯B) 0kWh は基本料金のみ 30 0 858
第1段階の上限(120kWh) 30 120 3,243
第2段階の開始(121kWh) 30 121 3,270
第2段階の上限(300kWh) 30 300 8,010
第3段階の開始(301kWh) 30 301 8,040
複数段階またがり 40 400 11,353
基本料金なし + 均一(おうちプラン) 0kWh は 0 円 30 0 0
通常使用(400kWh) 30 400 11,520
アンペア非対応プランの除外 20A でずっとも電気1 が除外される 20 400 含まれない
20A で Looop おうちプランは含まれる 20 400 含まれる
横断 全プラン対応 A で 4 プラン返る 30 400 4件
price 昇順で並ぶ 30 400 ソート済み
戻り値の形 各要素が 3 キーのみ持つ 30 400 keys 一致
price は Integer 30 400 Integer 型
入力バリデーション サポート外アンペア (25A) で ArgumentError raises
Float アンペア (30.0) で ArgumentError raises
Float の kwh (400.5) で ArgumentError raises
負の kwh で ArgumentError raises
MAX_KWH 超過で ArgumentError raises
Integer-coercible な文字列は正常計算 整数と同結果

@en-Barry en-Barry linked an issue May 7, 2026 that may be closed by this pull request
@en-Barry en-Barry changed the title feat: 電気料金シミュレーションサービスを実装 電気料金シミュレーションサービスを実装 May 8, 2026
@en-Barry en-Barry linked an issue May 8, 2026 that may be closed by this pull request
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/models-yaml-setup branch from e99d28f to 50d70c4 Compare May 11, 2026 04:59
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/electricity-bill-simulator branch from a640b2c to 8169e8d Compare May 11, 2026 05:01
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/models-yaml-setup branch from 50d70c4 to c0b6d7d Compare May 11, 2026 05:57
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/electricity-bill-simulator branch from 8169e8d to 64807d7 Compare May 11, 2026 05:57
Repository owner deleted a comment from vercel Bot May 11, 2026
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/models-yaml-setup branch from c0b6d7d to ce30231 Compare May 11, 2026 08:55
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/electricity-bill-simulator branch from 64807d7 to ba0c72a Compare May 11, 2026 08:56
Repository owner deleted a comment from vercel Bot May 11, 2026
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/electricity-bill-simulator branch from ba0c72a to 8a9a3cd Compare May 11, 2026 10:03
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/models-yaml-setup branch from ce30231 to fa4507f Compare May 12, 2026 05:43
en-Barry and others added 5 commits May 12, 2026 15:06
サービス未実装のため、この時点では NameError で全 fail する想定。
TDD の red を履歴として残すために実装より先にコミットする。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Closes #6

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Integer() は Float を黙って切り捨てるため、parse_integer! で Float を事前チェックする。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@en-Barry en-Barry force-pushed the feature/2605/en-Barry/electricity-bill-simulator branch from 8a9a3cd to ce9f7d0 Compare May 12, 2026 06:06
横断 / 全プラン対応のアンペアでは 4 プラン全て返る (ampere: 30) で
同等のカバレッジが得られるため重複テストを除去。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Base automatically changed from feature/2605/en-Barry/models-yaml-setup to develop May 12, 2026 10:27
@en-Barry en-Barry merged commit fd0e988 into develop May 12, 2026
@en-Barry en-Barry deleted the feature/2605/en-Barry/electricity-bill-simulator branch May 12, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

サービスクラス + ユニットテスト(TDD) 電気料金シミュレーションAPI実装(PR1: 基本要件)

1 participant