From 512c9f78e51e7d2c8a1a7889e03450a623d7899c Mon Sep 17 00:00:00 2001 From: tominaga Date: Sat, 2 Nov 2019 22:09:53 +0900 Subject: [PATCH] add if statement test --- spec/basic/step02_if_for_spec.rb | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 spec/basic/step02_if_for_spec.rb diff --git a/spec/basic/step02_if_for_spec.rb b/spec/basic/step02_if_for_spec.rb new file mode 100644 index 0000000..a12d764 --- /dev/null +++ b/spec/basic/step02_if_for_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' + +describe 'Step02IfForSpec' do + context 'if statement' do + # What string is sea variable at the method end? + # メソッド終了時の変数 sea の中身は? + it 'spec if basic' do + sea = 904 + if sea >= 904 + sea = 2001 + end + log(sea) + end + + # Same as the previous method question. (前のメソッドの質問と同じ) + it 'spec if else basic' do + sea = 904 + if sea >= 904 + sea = 2001 + else + sea = 7 + end + log(sea) # your answer? => + end + + # Same as the previous method question. (前のメソッドの質問と同じ) + it 'spec if elsif basic' do + sea = 904 + if sea > 904 + sea = 2001 + elsif sea >= 904 + sea = 7 + elsif sea >= 903 + sea = 8 + else + sea = 9 + end + log(sea) # your answer? => + end + + # Same as the previous method question. (前のメソッドの質問と同じ) + it 'spec if elsif nested' do + land = false + sea = 904 + if sea > 904 + sea = 2001 + elsif land && sea >= 904 + sea = 7 + elsif sea >= 903 || land + sea = 8 + if !land + land = true + elsif sea <= 903 + sea += 1 + end + else + sea = 9 + end + if land + sea = 10 + end + log(sea) # your answer? => + end + end +end +