Skip to content

Conversation

@big-noble
Copy link

@big-noble big-noble commented May 7, 2024

概要

serverside_challenge_1 の課題を実装いたしました。

  • ご案内いただきました通り、Laravelで構築&実装しております

API仕様

  • 契約アンペア数と使用量(kWh/月)を受け取り、プランごとの電気料金を返却する
  • APIのエンドポイントは以下のとおり(localhostの場合)
    http://localhost/api/plan/index?ampere=10&use_power=100
  • JSON形式で結果を返却
  • 一般的な電力会社の約款に則り、電気料金の端数は切り捨てとする
    *電力会社別に端数処理が異なる場合、Yamlに端数処理の区分を追加して対応することを想定する

動作環境

laradockを使用し、簡易的にDocker環境を構築して実装しております

動作環境の構築手順につきましては、以下のREADMEをご参照ください。
https://github.com/big-noble/coding-challenge/blob/master/serverside_challenge_1/challenges/big-noble/README.md

テストコード

実行方法

cd coding-challenge/serverside_challenge_1/challenges/big-noble/laradoc
docker-compose exec --user=laradock workspace php artisan test

実行結果

   PASS  Tests\Unit\ExampleTest
  ✓ that true is true                                                                                       0.06s

   PASS  PlanRequestTest
  ✓ validation with data set "ok"                                                                           1.75s
  ✓ validation with data set "ng:アンペア数必須 n u l l"
0.20s
  ✓ validation with data set "ng:アンペア数必須キーなし"
    0.06s
  ✓ validation with data set "ng:使用量必須 n u l l"                                                             0.06s
  ✓ validation with data set "ng:使用量必須キーなし"
  0.06s
  ✓ validation with data set "ng:存在しないアンペア数"
   0.05s
  ✓ validation with data set "ng:使用量が整数でない"
  0.06s

   PASS  Tests\Unit\PlanTest
  ✓ basic test with data set "10a 10kwh"                                                                    0.07s
  ✓ basic test with data set "15a 120kwh"                                                                   0.05s
  ✓ basic test with data set "20a 121kwh"                                                                   0.06s
  ✓ basic test with data set "30a 300kwh"                                                                   0.06s
  ✓ basic test with data set "40a 301kwh"                                                                   0.05s
  ✓ basic test with data set "50a 600kwh"                                                                   0.04s
  ✓ basic test with data set "60a 601kwh"                                                                   0.08s

   PASS  Tests\Feature\ExampleTest
  ✓ the application returns a successful response                                                           0.48s

   PASS  Tests\Feature\PlanTest
  ✓ success                                                                                                 0.16s
  ✓ error                                                                                                   0.07s

  Tests:    18 passed (24 assertions)
  Duration: 4.24s

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.

1 participant