package com.hubspot.jinjava.lib.filter;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import com.google.common.collect.ImmutableMap;
import com.hubspot.jinjava.BaseJinjavaTest;
import com.hubspot.jinjava.interpret.FatalTemplateErrorsException;
import org.junit.Test;

public class DivideFilterTest extends BaseJinjavaTest {

  @Test
  public void itDivides() {
    assertThat(
        jinjava.render(
          "{{ numerator|divide(denominator) }}",
          ImmutableMap.of("numerator", 10, "denominator", 2)
        )
      )
      .isEqualTo("5");
    assertThat(
        jinjava.render(
          "{{ numerator // denominator }}",
          ImmutableMap.of("numerator", 10, "denominator", 2)
        )
      )
      .isEqualTo("5");
    assertThat(
        jinjava.render(
          "{{ numerator / denominator }}",
          ImmutableMap.of("numerator", 10, "denominator", 2)
        )
      )
      .isEqualTo("5.0");
  }

  @Test
  public void itDividesIntegersWithNonIntegerResult() {
    assertThat(
        jinjava.render(
          "{{ numerator|divide(denominator) }} {{ numerator / denominator }}",
          ImmutableMap.of("numerator", 9, "denominator", 10)
        )
      )
      .isEqualTo("0.9 0.9");
  }

  @Test
  public void itThrowsAnExceptionOnDivideByZero() {
    assertThatExceptionOfType(FatalTemplateErrorsException.class)
      .isThrownBy(
        () -> {
          jinjava.render(
            "{{ numerator|divide(denominator) }}",
            ImmutableMap.of("numerator", 10, "denominator", 0)
          );
        }
      );
  }
}

@@ -95,81 +95,8 @@
 hat;
-%0Aimport static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 %0A%0Aim
@@ -188,75 +188,8 @@
 st;%0A
-import com.hubspot.jinjava.interpret.FatalTemplateErrorsException;%0A
 impo
@@ -480,32 +480,34 @@
    .isEqualTo(%225
+.0
 %22);%0A    assertTh
@@ -1126,32 +1126,32 @@
       )%0A      )%0A
+
       .isEqualTo
@@ -1170,345 +1170,7 @@
 %0A  %7D
-%0A%0A  @Test%0A  public void itThrowsAnExceptionOnDivideByZero() %7B%0A    assertThatExceptionOfType(FatalTemplateErrorsException.class)%0A      .isThrownBy(%0A        () -%3E %7B%0A          jinjava.render(%0A            %22%7B%7B numerator%7Cdivide(denominator) %7D%7D%22,%0A            ImmutableMap.of(%22numerator%22, 10, %22denominator%22, 0)%0A          );%0A        %7D%0A      );%0A  %7D
 %0A%7D%0A

fix tests