import {
  calculateCapacity,
  calculateMaxCapacity,
} from './calc-capacity.helper';

describe('calculateCapacity', () => {
  it('should return capacityValue2 when it is smaller than capacityValue3', () => {
    // Arrange
    const input = { capacityValue2: 5, capacityValue3: 10 };

    // Act
    const result = calculateCapacity(input);

    // Assert
    expect(result).toBe(5);
  });

  it('should return capacityValue3 when it is smaller than capacityValue2', () => {
    // Arrange
    const input = { capacityValue2: 15, capacityValue3: 8 };

    // Act
    const result = calculateCapacity(input);

    // Assert
    expect(result).toBe(8);
  });

  it('should return capacityValue3 when both values are equal', () => {
    // Arrange
    const input = { capacityValue2: 10, capacityValue3: 10 };

    // Act
    const result = calculateCapacity(input);

    // Assert
    expect(result).toBe(10);
  });

  it('should handle zero values correctly', () => {
    // Arrange
    const input = { capacityValue2: 0, capacityValue3: 5 };

    // Act
    const result = calculateCapacity(input);

    // Assert
    expect(result).toBe(0);
  });

  it('should handle negative values correctly', () => {
    // Arrange
    const input = { capacityValue2: -3, capacityValue3: 2 };

    // Act
    const result = calculateCapacity(input);

    // Assert
    expect(result).toBe(-3);
  });
});

describe('calculateMaxCapacity', () => {
  it('should return capacityValue2 when capacityValue4 is greater than capacityValue2', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 15,
      capacityValue4: 20,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(10);
  });

  it('should return capacityValue4 when it is positive and less than capacityValue2', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 15,
      capacityValue4: 8,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(8);
  });

  it('should return capacityValue2 when capacityValue4 is zero and capacityValue3 is greater than capacityValue2', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 15,
      capacityValue4: 0,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(10);
  });

  it('should return capacityValue3 when capacityValue4 is zero and capacityValue3 is positive and less than capacityValue2', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 8,
      capacityValue4: 0,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(8);
  });

  it('should return comparer when it is greater than calculated max capacity', () => {
    // Arrange
    const input = {
      capacityValue2: 5,
      capacityValue3: 3,
      capacityValue4: 2,
      comparer: 10,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(10);
  });

  it('should handle undefined capacityValue4 with default value 0', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 15,
      capacityValue4: undefined,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(10);
  });

  it('should handle all zero capacity values', () => {
    // Arrange
    const input = {
      capacityValue2: 0,
      capacityValue3: 0,
      capacityValue4: 0,
      comparer: 3,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(3);
  });

  it('should handle negative capacity values', () => {
    // Arrange
    const input = {
      capacityValue2: -5,
      capacityValue3: -3,
      capacityValue4: -2,
      comparer: 1,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(1);
  });

  it('should use default values for optional parameters when not provided', () => {
    // Arrange
    const input = {
      capacityValue2: 10,
      capacityValue3: 8,
      capacityValue4: undefined,
      comparer: 5,
    };

    // Act
    const result = calculateMaxCapacity(input);

    // Assert
    expect(result).toBe(8);
  });
});
