/**
 * Created by AAravindan on 5/4/16.
 */
var IchimokuCloud = require('../../lib/ichimoku/IchimokuCloud').IchimokuCloud
var assert = require('assert')
var data = require('../data')

var ichimokuInput = {
  high  : [130,135.475005,134.699995,147.899995,153.199995,155,151.875,150.600005,151,151,168.875,180.925005,212.350005,255,248.949995,255,291.399995,302.95001,310,300,325,316.524995,229.125,245.25,277.5,259.875,300,293.5,273.95001,275,298.899995,300.399995,288.45001,277.875,337.5,355.95001,399.5,420,404.95001,432.92499,450.42499,468,362.17499,404,525,592.2,532,550,569.95,598.4,620,657.975,652.5,714,722.2,691.9,813.3,898.9,900,974.25,982.9,1207.5,1427.225,1464,1494,1649,1321,1214.19995,1359,1354.5,1222,1169.225,1188,1112.5,981.5,752.6,703.5,695,707.05,791.7,920,1267.5,1189.5,1091.5,1062.5,1119.94995,1141.65,1112.94995,1120,1149.9,1056.35,1111,1149.7,1093.4,1093.95,1094.45,1031,1048.5,1110,1124.9,1075,1091.4,1009.4,1055,1065.9,986.79999,967,907,838.90002,859,904,905,844.59998,827.90002,864.70001,830,762.90002,751.40002,742.95001,746.09998,824.90002,881.59998,862,814.90002,849.79999,955,901,869.40002,826.59998,855,873,927.90002,882.84998,901,918,926.54999,909,898.25,829.79999,939.79999,988.75,1145.25,1133,1043.3,1023,1041.3,1003.7,1017.35,991.95001,934.5,943.79999,909.65002,944.29999,915.40002,1014.1,1067.85,1013.85,899.5,974.79999,992.5,1019.7,1089.75,1041.8,1056,1069.9,994.95001],
  low   : [117.15,126,109.025,125.875,141.100005,131.649995,138.274995,137.050005,132.375,128.574995,145.625,161.625,171.800005,196,211.25,223.100005,217.5,263.625,269.5,252.625,261.100005,190.850005,204.574995,200,224.25,234.300005,256.125,243.5,236.050005,245,264.32501,269.54999,256,257.79999,264.274995,304.649995,341.54999,359.5,367.5,367.5,413.5,290.04999,341.75,351.04999,400.5,420,403.5,470.75,476,536.55,569.25,610.05,588.175,632.05,652.55,624.1,652.625,765.625,823.55,838.05,841.6,960.625,1098.85,1288.5,1325.775,1060,1117.5,1060,1121.75,1195.125,978.125,960,1026.4,882.5,465,516.05,512.5,532.5,600.675,557.65,748.675,918,950,858.55,933.8,961.65,961,901.125,990,1018.1,959.15002,979.40002,1012,976,995.09998,1007.25,915,921,990,958.29999,978.75,902,885.09998,964,970,898.34998,828.09998,823.15002,712,747.54999,761.75,751,689,687.15002,765.34998,718,723.70001,673.04999,673.40002,706.65002,730.54999,760.04999,791.70001,761.09998,789.75,836.25,805.75,764.40002,764.15002,779.20001,775.29999,839,763.90002,819.09998,817.70001,835.25,836.75,822.20001,793.09998,797.15002,929.09998,925,1000,958.5,971,917.29999,911.54999,963.40002,859.70001,831.20001,836.59998,796.45001,813.09998,857.20001,873.65002,983.15002,818,825.09998,858.59998,909.95001,912.84998,976.70001,888.09998,964.65002,978.84998,966.35],
  conversionPeriod: 9,
  basePeriod: 26,
  spanPeriod: 52,
  displacement: 26
}

var expectedOutput = [
  {
    "conversion": 504.512495,
    "base": 447.0125025,
    "spanA": 475.76249874999996,
    "spanB": 383.5
  },
  {
    "conversion": 529.2375,
    "base": 447.0125025,
    "spanA": 488.12500124999997,
    "spanB": 383.5
  },
  {
    "conversion": 558.75,
    "base": 475.0250025,
    "spanA": 516.88750125,
    "spanB": 411.5125
  },
  {
    "conversion": 562.85,
    "base": 483.6,
    "spanA": 523.225,
    "spanB": 424.0375
  },
  {
    "conversion": 596.475,
    "base": 489.1,
    "spanA": 542.7875,
    "spanB": 425.3874975
  },
  {
    "conversion": 644.65,
    "base": 534.65,
    "spanA": 589.65,
    "spanB": 470.93749749999995
  },
  {
    "conversion": 717.7249999999999,
    "base": 577.45,
    "spanA": 647.5875,
    "spanB": 513.7374975
  },
  {
    "conversion": 734.625,
    "base": 578.899995,
    "spanA": 656.7624975,
    "spanB": 514.2874975
  },
  {
    "conversion": 781.2125,
    "base": 619.2624975,
    "spanA": 700.23749875,
    "spanB": 551.4124975
  },
  {
    "conversion": 785.5374999999999,
    "base": 636.474995,
    "spanA": 711.0062475,
    "spanB": 555.7374975
  },
  {
    "conversion": 915.8,
    "base": 748.774995,
    "spanA": 832.2874975,
    "spanB": 676.5625
  },
  {
    "conversion": 1025.6625,
    "base": 858.637495,
    "spanA": 942.1499974999999,
    "spanB": 794.425
  },
  {
    "conversion": 1044.05,
    "base": 877.024995,
    "spanA": 960.5374975,
    "spanB": 817.9000025
  },
  {
    "conversion": 1073.3125,
    "base": 892.024995,
    "spanA": 982.6687475,
    "spanB": 842.4250025
  },
  {
    "conversion": 1207.3125,
    "base": 969.524995,
    "spanA": 1088.4187474999999,
    "spanB": 919.9250025
  },
  {
    "conversion": 1236.275,
    "base": 969.524995,
    "spanA": 1102.8999975000002,
    "spanB": 919.9250025
  },
  {
    "conversion": 1243.525,
    "base": 995.375,
    "spanA": 1119.45,
    "spanB": 919.9250025
  },
  {
    "conversion": 1245.3,
    "base": 1000.024995,
    "spanA": 1122.6624975,
    "spanB": 919.9250025
  },
  {
    "conversion": 1304.8125,
    "base": 1024.75,
    "spanA": 1164.78125,
    "spanB": 919.9250025
  },
  {
    "conversion": 1313.5625,
    "base": 1026.25,
    "spanA": 1169.90625,
    "spanB": 919.9250025
  },
  {
    "conversion": 1304.5,
    "base": 1026.25,
    "spanA": 1165.375,
    "spanB": 919.9250025
  },
  {
    "conversion": 1304.5,
    "base": 1059.875,
    "spanA": 1182.1875,
    "spanB": 919.9250025
  },
  {
    "conversion": 1265.75,
    "base": 1062.5,
    "spanA": 1164.125,
    "spanB": 924.5
  },
  {
    "conversion": 912,
    "base": 1057,
    "spanA": 984.5,
    "spanB": 924.5
  },
  {
    "conversion": 912,
    "base": 1057,
    "spanA": 984.5,
    "spanB": 936.625
  },
  {
    "conversion": 912,
    "base": 1057,
    "spanA": 984.5,
    "spanB": 941.6500025
  },
  {
    "conversion": 909.75,
    "base": 1057,
    "spanA": 983.375,
    "spanB": 942.5250025
  },
  {
    "conversion": 843.5,
    "base": 1057,
    "spanA": 950.25,
    "spanB": 942.5250025
  },
  {
    "conversion": 826.5,
    "base": 1057,
    "spanA": 941.75,
    "spanB": 942.5250025
  },
  {
    "conversion": 826.5,
    "base": 1057,
    "spanA": 941.75,
    "spanB": 947
  },
  {
    "conversion": 866.25,
    "base": 1057,
    "spanA": 961.625,
    "spanB": 952.5
  },
  {
    "conversion": 866.25,
    "base": 1057,
    "spanA": 961.625,
    "spanB": 952.5
  },
  {
    "conversion": 890,
    "base": 1057,
    "spanA": 973.5,
    "spanB": 952.5
  },
  {
    "conversion": 890,
    "base": 1057,
    "spanA": 973.5,
    "spanB": 953.399995
  },
  {
    "conversion": 900,
    "base": 1057,
    "spanA": 978.5,
    "spanB": 956.6374975
  },
  {
    "conversion": 912.575,
    "base": 1057,
    "spanA": 984.7875,
    "spanB": 969.524995
  },
  {
    "conversion": 912.575,
    "base": 1057,
    "spanA": 984.7875,
    "spanB": 969.524995
  },
  {
    "conversion": 1008.0875,
    "base": 1057,
    "spanA": 1032.54375,
    "spanB": 969.524995
  },
  {
    "conversion": 1063.025,
    "base": 1057,
    "spanA": 1060.0125,
    "spanB": 969.524995
  },
  {
    "conversion": 1024.025,
    "base": 1057,
    "spanA": 1040.5125,
    "spanB": 969.524995
  },
  {
    "conversion": 1004.225,
    "base": 912,
    "spanA": 958.1125,
    "spanB": 969.524995
  },
  {
    "conversion": 1025.5125,
    "base": 912,
    "spanA": 968.75625,
    "spanB": 969.524995
  },
  {
    "conversion": 1025.5125,
    "base": 912,
    "spanA": 968.75625,
    "spanB": 995.375
  },
  {
    "conversion": 1025.5125,
    "base": 909.75,
    "spanA": 967.63125,
    "spanB": 1000.024995
  },
  {
    "conversion": 1025.5125,
    "base": 866.25,
    "spanA": 945.88125,
    "spanB": 1024.75
  },
  {
    "conversion": 1032.45,
    "base": 866.25,
    "spanA": 949.35,
    "spanB": 1026.25
  },
  {
    "conversion": 1032.45,
    "base": 866.25,
    "spanA": 949.35,
    "spanB": 1026.25
  },
  {
    "conversion": 1032.35,
    "base": 866.25,
    "spanA": 949.3,
    "spanB": 1057
  },
  {
    "conversion": 1032.35,
    "base": 866.25,
    "spanA": 949.3,
    "spanB": 1057
  },
  {
    "conversion": 1032.35,
    "base": 890,
    "spanA": 961.175,
    "spanB": 1057
  },
  {
    "conversion": 1013.45,
    "base": 890,
    "spanA": 951.725,
    "spanB": 1057
  },
  {
    "conversion": 1004.99999,
    "base": 900,
    "spanA": 952.499995,
    "spanB": 1057
  },
  {
    "conversion": 1004.99999,
    "base": 912.575,
    "spanA": 958.787495,
    "spanB": 1057
  },
  {
    "conversion": 1004.99999,
    "base": 912.575,
    "spanA": 958.787495,
    "spanB": 1057
  },
  {
    "conversion": 1004.99999,
    "base": 1008.0875,
    "spanA": 1006.543745,
    "spanB": 1057
  },
  {
    "conversion": 976.49999,
    "base": 1047.79999,
    "spanA": 1012.14999,
    "spanB": 1057
  },
  {
    "conversion": 974.0250100000001,
    "base": 1006.32501,
    "spanA": 990.17501,
    "spanB": 1057
  },
  {
    "conversion": 901.7,
    "base": 930.95,
    "spanA": 916.325,
    "spanB": 1057
  },
  {
    "conversion": 901.7,
    "base": 930.95,
    "spanA": 916.325,
    "spanB": 1057
  },
  {
    "conversion": 888.95,
    "base": 930.95,
    "spanA": 909.95,
    "spanB": 1057
  },
  {
    "conversion": 888.95,
    "base": 930.95,
    "spanA": 909.95,
    "spanB": 1057
  },
  {
    "conversion": 877.45,
    "base": 919.45,
    "spanA": 898.45,
    "spanB": 1057
  },
  {
    "conversion": 836.975005,
    "base": 918.5250100000001,
    "spanA": 877.7500075,
    "spanB": 1057
  },
  {
    "conversion": 827.07501,
    "base": 918.5250100000001,
    "spanA": 872.80001,
    "spanB": 1057
  },
  {
    "conversion": 797.07501,
    "base": 918.42501,
    "spanA": 857.75001,
    "spanB": 1057
  },
  {
    "conversion": 796.07501,
    "base": 918.42501,
    "spanA": 857.25001,
    "spanB": 1057
  },
  {
    "conversion": 789.024995,
    "base": 911.374995,
    "spanA": 850.199995,
    "spanB": 912
  },
  {
    "conversion": 789.024995,
    "base": 898.974995,
    "spanA": 843.999995,
    "spanB": 912
  },
  {
    "conversion": 789.024995,
    "base": 898.974995,
    "spanA": 843.999995,
    "spanB": 912
  },
  {
    "conversion": 768.875,
    "base": 898.974995,
    "spanA": 833.9249975,
    "spanB": 909.75
  },
  {
    "conversion": 777.324985,
    "base": 898.974995,
    "spanA": 838.14999,
    "spanB": 866.25
  },
  {
    "conversion": 777.324985,
    "base": 898.974995,
    "spanA": 838.14999,
    "spanB": 866.25
  },
  {
    "conversion": 777.324985,
    "base": 898.974995,
    "spanA": 838.14999,
    "spanB": 866.25
  },
  {
    "conversion": 777.324985,
    "base": 898.974995,
    "spanA": 838.14999,
    "spanB": 866.25
  },
  {
    "conversion": 814.024995,
    "base": 882.224995,
    "spanA": 848.124995,
    "spanB": 866.25
  },
  {
    "conversion": 814.20001,
    "base": 882.224995,
    "spanA": 848.2125025,
    "spanB": 890
  },
  {
    "conversion": 830.82501,
    "base": 869.474995,
    "spanA": 850.1500025,
    "spanB": 890
  },
  {
    "conversion": 842.774995,
    "base": 869.474995,
    "spanA": 856.124995,
    "spanB": 900
  },
  {
    "conversion": 857.524995,
    "base": 869.474995,
    "spanA": 863.499995,
    "spanB": 912.575
  },
  {
    "conversion": 858.04999,
    "base": 829.92499,
    "spanA": 843.98749,
    "spanB": 912.575
  },
  {
    "conversion": 858.04999,
    "base": 820.024995,
    "spanA": 839.0374925,
    "spanB": 970.274995
  },
  {
    "conversion": 859.45001,
    "base": 814.024995,
    "spanA": 836.7375025,
    "spanB": 970.274995
  },
  {
    "conversion": 859.45001,
    "base": 814.024995,
    "spanA": 836.7375025,
    "spanB": 931.274995
  },
  {
    "conversion": 845.90002,
    "base": 814.024995,
    "spanA": 829.9625075,
    "spanB": 911.474995
  },
  {
    "conversion": 845.90002,
    "base": 814.024995,
    "spanA": 829.9625075,
    "spanB": 911.474995
  },
  {
    "conversion": 845.90002,
    "base": 814.024995,
    "spanA": 829.9625075,
    "spanB": 911.474995
  },
  {
    "conversion": 845.90002,
    "base": 814.024995,
    "spanA": 829.9625075,
    "spanB": 911.474995
  },
  {
    "conversion": 845.90002,
    "base": 814.024995,
    "spanA": 829.9625075,
    "spanB": 911.474995
  },
  {
    "conversion": 851.850005,
    "base": 814.024995,
    "spanA": 832.9375,
    "spanB": 911.474995
  },
  {
    "conversion": 876.32501,
    "base": 830.899995,
    "spanA": 853.6125025,
    "spanB": 911.474995
  },
  {
    "conversion": 969.17499,
    "base": 909.149995,
    "spanA": 939.1624925,
    "spanB": 911.374995
  },
  {
    "conversion": 969.17499,
    "base": 909.149995,
    "spanA": 939.1624925,
    "spanB": 911.374995
  },
  {
    "conversion": 969.17499,
    "base": 909.32501,
    "spanA": 939.25,
    "spanB": 911.374995
  },
  {
    "conversion": 969.17499,
    "base": 925.95001,
    "spanA": 947.5625,
    "spanB": 909.149995
  },
  {
    "conversion": 969.17499,
    "base": 937.899995,
    "spanA": 953.5374925,
    "spanB": 909.149995
  },
  {
    "conversion": 969.17499,
    "base": 952.649995,
    "spanA": 960.9124925,
    "spanB": 909.149995
  },
  {
    "conversion": 971.20001,
    "base": 953.17499,
    "spanA": 962.1875,
    "spanB": 909.149995
  },
  {
    "conversion": 1002.475005,
    "base": 953.17499,
    "spanA": 977.8249975,
    "spanB": 909.149995
  },
  {
    "conversion": 988.225005,
    "base": 954.57501,
    "spanA": 971.4000075,
    "spanB": 909.149995
  },
  {
    "conversion": 982.100005,
    "base": 954.57501,
    "spanA": 968.3375075,
    "spanB": 909.149995
  },
  {
    "conversion": 919.875005,
    "base": 954.57501,
    "spanA": 937.2250075,
    "spanB": 909.149995
  },
  {
    "conversion": 918.875005,
    "base": 954.57501,
    "spanA": 936.7250075,
    "spanB": 909.149995
  },
  {
    "conversion": 918.875005,
    "base": 954.57501,
    "spanA": 936.7250075,
    "spanB": 909.149995
  },
  {
    "conversion": 906.900005,
    "base": 954.57501,
    "spanA": 930.7375075,
    "spanB": 909.149995
  },
  {
    "conversion": 932.150005,
    "base": 954.57501,
    "spanA": 943.3625075,
    "spanB": 909.149995
  },
  {
    "conversion": 932.150005,
    "base": 954.57501,
    "spanA": 943.3625075,
    "spanB": 909.149995
  },
  {
    "conversion": 932.150005,
    "base": 954.57501,
    "spanA": 943.3625075,
    "spanB": 909.149995
  },
  {
    "conversion": 932.150005,
    "base": 969.17499,
    "spanA": 950.6624975,
    "spanB": 909.149995
  },
  {
    "conversion": 932.150005,
    "base": 969.17499,
    "spanA": 950.6624975,
    "spanB": 909.149995
  },
  {
    "conversion": 940.4749899999999,
    "base": 969.17499,
    "spanA": 954.82499,
    "spanB": 909.149995
  },
  {
    "conversion": 953.875,
    "base": 969.17499,
    "spanA": 961.524995,
    "spanB": 909.149995
  },
  {
    "conversion": 953.875,
    "base": 969.17499,
    "spanA": 961.524995,
    "spanB": 909.149995
  },
  {
    "conversion": 953.875,
    "base": 969.17499,
    "spanA": 961.524995,
    "spanB": 909.149995
  },
  {
    "conversion": 953.875,
    "base": 970.850005,
    "spanA": 962.3625025,
    "spanB": 909.149995
  },
  {
    "conversion": 957.42499,
    "base": 970.850005,
    "spanA": 964.1374975,
    "spanB": 909.149995
  }
]

var input;

describe('Ichimoku cloud', function () {
  beforeEach(function () {
    input = JSON.parse(JSON.stringify(ichimokuInput))
  })

  it('should calculate IchimokuCloud using the calculate method', function () {
    var result = IchimokuCloud.calculate(input)
    // require('fs').writeFileSync('ichimoku', JSON.stringify(result, null, 2))
    assert.deepEqual(result, expectedOutput, 'Wrong Results')
  })

  it('should be able to get ichimoku cloud from the get results', function () {
    var ichimoku = new IchimokuCloud(input)
    assert.deepEqual(ichimoku.getResult(), expectedOutput, 'Wrong Results')
  })

  it('should be able to get IchimokuCloud for the next bar using nextValue', function () {
    input.high = []
    input.low = []
    var ichimoku = new IchimokuCloud(input)
    var results = []
    ichimokuInput.high.forEach((high, index) => {
      var result = ichimoku.nextValue({ high: high, low: ichimokuInput.low[index]})
      if (result)
        results.push(result)
    })
    assert.deepEqual(results, expectedOutput, 'Wrong Results')
  })
})
