Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

test_todo_2_json.rb

ソースコード

# encoding: Shift_JIS
require 'test/unit'
require_relative '../ttm/todo_2_json'

class TestTodo2Json < Test::Unit::TestCase
  def setup
    @todo_2_json = Todo2Json.new
  end

  # def teardown
  # end

=begin
TODOから変換されたJSONの取得
正常系
【入力】
  "準備[アクティビティのコミット,メールチェック]|1|2012/02/06 09:01:28|2012/02/06 09:08:34|0時間7分6秒"
【期待値】
  "todo":{
    "task":"準備[アクティビティのコミット,メールチェック]",
    "estimate":"1",
    "actualResultsTime":"0時間7分6秒"
  }
=end
  def test_get_todo_json
    todo = "準備[アクティビティのコミット,メールチェック]|1|2012/02/06 09:01:28|2012/02/06 09:08:34|0時間7分6秒"
    json = @todo_2_json.get_todo_json todo
    
    expected = <<"EOS"
"todo":{
  "task":"準備[アクティビティのコミット,メールチェック]",
  "estimate":"1",
  "actualResultsTime":"0時間7分6秒"
}
EOS
    assert_equal(expected.chomp, json)
  end
  
=begin
TODOから変換されたJSONの取得
異常系
【入力】
  nil
【期待値】
  ""(空文字)
=end
  def test_get_todo_json_nil
    todo = nil
    json = @todo_2_json.get_todo_json todo
    
    expected = ""
    assert_equal(expected, json)
  end

=begin
TODOから変換されたJSONの取得
異常系
【入力】
  ""(空文字)
【期待値】
  ""(空文字)
=end
  def test_get_todo_json_empty
    todo = ""
    json = @todo_2_json.get_todo_json todo
    
    expected = ""
    assert_equal(expected, json)
  end
  

=begin
TODOから変換されたJSONの取得
異常系
【入力】
  a|b|c|d|e|f(区切り文字が5つ)
  a|b|c|d(区切り文字が3つ)
  abcde(区切り文字が0)
【期待値】
  ""(空文字)
=end
  def test_get_todo_json_length
    todo = "a|b|c|d|e|f"
    json = @todo_2_json.get_todo_json(todo)
    expected = ""
    assert_equal(expected, json)

    todo = "a|b|c|d"
    json = @todo_2_json.get_todo_json todo
    expected = ""
    assert_equal(expected, json)

    todo = "abcde"
    json = @todo_2_json.get_todo_json todo
    expected = ""
    assert_equal(expected, json)
  end
=begin
===Contract TODOの区切り文字数が3以外なら不正
=end

=begin
デイリーから変換されたJSONの取得
正常系
【入力】
  2012/02/08
  タスク1|見積1|開始時間1|終了時間1|実績時間1
  タスク2|見積2|開始時間2|終了時間2|実績時間2
  タスク3|見積3|開始時間3|終了時間3|実績時間3
【期待値】
    {"date":"2012/02/08"},
    [
      {
        "todo":{
        "task":"タスク1",
        "estimate":"見積1",
        "actualResultsTime":"実績時間1"
        }
      },
      {
        "todo":{
          "task":"タスク2",
          "estimate":"見積2",
          "actualResultsTime":"実績時間2"
        }
      },
      {
        "todo":{
          "task":"タスク3",
          "estimate":"見積3",
          "actualResultsTime":"実績時間3"
        }
      }
    ]
=end
  def test_get_daily_json
    daily =<<"EOS"
2012/02/08
タスク1|見積1|開始時間1|終了時間1|実績時間1
タスク2|見積2|開始時間2|終了時間2|実績時間2
タスク3|見積3|開始時間3|終了時間3|実績時間3
EOS
    json = @todo_2_json.get_daily_json daily
    
    expected =<<"EOS"
{"date":"2012/02/08"},
[
  {
"todo":{
  "task":"タスク1",
  "estimate":"見積1",
  "actualResultsTime":"実績時間1"
}
  },
  {
"todo":{
  "task":"タスク2",
  "estimate":"見積2",
  "actualResultsTime":"実績時間2"
}
  },
  {
"todo":{
  "task":"タスク3",
  "estimate":"見積3",
  "actualResultsTime":"実績時間3"
}
  }
]
EOS
    assert_equal(expected, json)
  end

=begin
デイリーから変換されたJSONの取得
異常系 入力データが空文字の場合
【入力】
  空文字
【期待値】
    空文字
=end
  def test_get_daily_json_empty
    daily = ""
    json = @todo_2_json.get_daily_json daily
    
    expected = ""
    assert_equal(expected, json)
  end
  
=begin
デイリーから変換されたJSONの取得
異常系 入力データがnilの場合
【入力】
  nil
【期待値】
    空文字
=end
  def test_get_daily_json_nil
    daily = nil
    json = @todo_2_json.get_daily_json daily
    
    expected = ""
    assert_equal(expected, json)
  end

=begin
デイリーから変換されたJSONの取得
異常系 入力データが1行しかなかった場合
【入力】
  2012/02/08
【期待値】
    空文字
=end
  def test_get_daily_json_1line
    daily = "2012/02/08"
    json = @todo_2_json.get_daily_json daily
    
    expected = ""
    assert_equal(expected, json)
  end

=begin
デイリーから変換されたJSONの取得
異常系 入力データが2行以上があるが、有効なTODOが1件もない場合は不正とし、空文字を返す
【入力】
2012/02/08
タスク1|見積1|開始時間1|終了時間1|実績時間1|aaa
タスク2|見積2|開始時間2|
タスク3見積3開始時間3終了時間3実績時間3
【期待値】
    空文字
=end
  def test_get_daily_json_1line
    daily =<<"EOS"
2012/02/08
タスク1|見積1|開始時間1|終了時間1|実績時間1|aaa
タスク2|見積2|開始時間2|
タスク3見積3開始時間3終了時間3実績時間3
EOS
    json = @todo_2_json.get_daily_json daily
    
    expected = ""
    assert_equal(expected, json)
  end

=begin
マンスリーから変換されたJSONの取得
正常系
【入力】
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|終了時間0208-1|実績時間0208-1
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1
■2012/02/10
タスク0210-1|見積0210-1|開始時間0210-1|終了時間0210-1|実績時間0210-1
【期待値】
  [
    {"date":"2012/02/08"},
    [
      {
        "todo":{
        "task":"タスク0208-1",
        "estimate":"見積0208-1",
        "actualResultsTime":"実績時間0208-1"
        }
      }
    ]
  ],
  [
    {"date":"2012/02/09"},
    [
      {
        "todo":{
        "task":"タスク0209-1",
        "estimate":"見積0209-1",
        "actualResultsTime":"実績時間0209-1"
        }
      }
    ]
  ],
  [
    {"date":"2012/02/10"},
    [
      {
        "todo":{
        "task":"タスク0210-1",
        "estimate":"見積0210-1",
        "actualResultsTime":"実績時間0210-1"
        }
      }
    ]
  ]
=end
  def test_get_monthly_json
    monthly =<<"EOS"
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|終了時間0208-1|実績時間0208-1
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1
■2012/02/10
タスク0210-1|見積0210-1|開始時間0210-1|終了時間0210-1|実績時間0210-1
EOS
    json = @todo_2_json.get_monthly_json monthly
    
    expected =<<"EOS"
  [
{"date":"2012/02/08"},
[
  {
"todo":{
  "task":"タスク0208-1",
  "estimate":"見積0208-1",
  "actualResultsTime":"実績時間0208-1"
}
  }
]
  ],
  [
{"date":"2012/02/09"},
[
  {
"todo":{
  "task":"タスク0209-1",
  "estimate":"見積0209-1",
  "actualResultsTime":"実績時間0209-1"
}
  }
]
  ],
  [
{"date":"2012/02/10"},
[
  {
"todo":{
  "task":"タスク0210-1",
  "estimate":"見積0210-1",
  "actualResultsTime":"実績時間0210-1"
}
  }
]
  ]
EOS
    assert_equal(expected.chomp, json)
    
  end
  
=begin
マンスリーから変換されたJSONの取得
異常系 空文字の場合はエラーとする
【入力】
  空文字
【期待値】
    例外 'incorrect input monthly'
=end
  def test_get_monthly_json_empty
    monthly = ""
    json = @todo_2_json.get_monthly_json monthly
    
    assert false
    
    rescue => exc
      expected = Todo2Json::ERR_MONTHLY
      assert_equal(expected, exc.message)
  end
  
=begin
マンスリーから変換されたJSONの取得
異常系 nilの場合はエラーとする
【入力】
  nil
【期待値】
    例外 'incorrect input monthly'
=end
  def test_get_monthly_json_nil
    monthly = nil
    json = @todo_2_json.get_monthly_json monthly
    
    assert false
    
    rescue => exc
      expected = Todo2Json::ERR_MONTHLY
      assert_equal(expected, exc.message)
  end

=begin
マンスリーから変換されたJSONの取得
異常系 区切り文字で分割した要素が2件以上なかった場合はエラーとする
【入力】
  空文字
【期待値】
    例外 'incorrect input monthly'
=end
  def test_get_monthly_json_nodata
    monthly = "あああ\nあああ"
    json = @todo_2_json.get_monthly_json monthly
    
    assert false
    
    rescue => exc
      expected = Todo2Json::ERR_MONTHLY
      assert_equal(expected, exc.message)
  end

=begin
マンスリーから変換されたJSONの取得
異常系 全てのデイリーの戻り値が空文字だった場合はエラーとする
【入力】
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|情報不足
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1|情報過多
【期待値】
    例外 'incorrect input monthly'
=end
  def test_get_monthly_json_no_valid_data
    monthly = <<"EOS"
■2012/02/08
タスク0208-1|見積0208-1|開始時間0208-1|情報不足
■2012/02/09
タスク0209-1|見積0209-1|開始時間0209-1|終了時間0209-1|実績時間0209-1|情報過多
EOS
    json = @todo_2_json.get_monthly_json monthly
    
    assert false
    
    rescue => exc
      expected = Todo2Json::ERR_MONTHLY
      assert_equal(expected, exc.message)
  end
end