require('matcher_combinators.luassert')

local BC = require('util.chooser')

describe('chooser', function()
  it('maximum', function()
    assert.equals(BC.battery_chooser({ 10, 20, 30, 10 }, 'maximum'), 30)
    assert.equals(BC.battery_chooser({ 10 }, 'maximum'), 10)
    assert.equals(BC.battery_chooser({ 50, 1 }, 'maximum'), 50)
    assert.equals(BC.battery_chooser({ 1, 50 }, 'maximum'), 50)
    assert.equals(BC.battery_chooser({ 50, 50, 50, -1, 50 }, 'maximum'), 50)
    assert.equals(BC.battery_chooser({ -50, -1, -10 }, 'maximum'), -1)
  end)
  it('average', function()
    assert.equals(BC.battery_chooser({ 1, 2, 3, 4, 5 }, 'average'), 3)
    assert.equals(BC.battery_chooser({ 1, 2, 3, 4, 5, 6 }, 'average'), 3)
    assert.equals(BC.battery_chooser({ 1, 2, 3, 4, 5, 6, 8 }, 'average'), 4)
    assert.equals(BC.battery_chooser({ 1, 1, 4, 5 }, 'average'), 2)
  end)
  it('index', function()
    assert.equals(BC.battery_chooser({ 10, 20, 30, 40, 50 }, 3), 30)
    assert.equals(BC.battery_chooser({ 10, 20, 30, 40, 50 }, 6), 10)
    assert.equals(BC.battery_chooser({ 10, 20, 30, 40, 50 }, -1), 10)
  end)
  it('invalid', function()
    assert.equals(BC.battery_chooser({}, 3), 0)
    assert.equals(BC.battery_chooser(nil, 3), 0)
  end)
end)
