package TestCase::Example {
  use SPVM::Example;
  
  sub call_precompile_sub : int () {
    my $nums = [1, 2, 3];
    my $total = SPVM::Example->sum($nums);
    
    if ($total == 6) {
      return 1;
    }
    return 0;
  }
  
  sub sin : int () {
    my $value = SPVM::Example->sin(SPVM::Example->PI());
    
    if ($value < 0.000001 && $value > -0.000001) {
      return 1;
    }
    return 0;
  }

  sub cos : int () {
    my $value = SPVM::Example->cos(SPVM::Example->PI() / 2.0);
    
    if ($value < 0.000001 && $value > -0.000001) {
      return 1;
    }
    return 0;
  }
  
  sub tan : int () {
    my $value = SPVM::Example->tan(SPVM::Example->PI() / 4.0);
    
    if ($value - 1.0 < 0.000001 && $value - 1.0 > -0.000001) {
      return 1;
    }
    return 0;
  }

  sub isinff: int () {
    if (SPVM::Example->isinff(SPVM::Example->INFINITYF())) {
      if (!SPVM::Example->isinff(SPVM::Example->NANF())) {
        if (!SPVM::Example->isinff(0.1f)) {
          return 1;
        }
      }
    }
    
    return 0;
  }

  sub isfinitef: int () {
    if (!SPVM::Example->isfinitef(SPVM::Example->INFINITYF())) {
      if (!SPVM::Example->isfinitef(SPVM::Example->NANF())) {
        if (SPVM::Example->isfinitef(0.1f)) {
          return 1;
        }
      }
    }
    
    return 0;
  }

  sub isnanf: int () {
    if (!SPVM::Example->isnanf(SPVM::Example->INFINITYF())) {
      if (SPVM::Example->isnanf(SPVM::Example->NANF())) {
        if (!SPVM::Example->isnanf(0.1f)) {
          return 1;
        }
      }
    }
    
    return 0;
  }
  
  sub float_pass_positive_infinity : int ($value : float) {
    if ($value == SPVM::Example->INFINITYF()) {
      return 1;
    }
    
    return 0;
  }
  
  sub float_pass_nan : int ($value : float) {
    if (SPVM::Example->isnanf($value)) {
      return 1;
    }
    
    return 0;
  }

  sub isinf : int () {
    if (SPVM::Example->isinf(SPVM::Example->INFINITY())) {
      if (!SPVM::Example->isinf(SPVM::Example->NAN())) {
        if (!SPVM::Example->isinf(0.1)) {
          return 1;
        }
      }
    }
    
    return 0;
  }

  sub isfinite : int () {
    if (!SPVM::Example->isfinite(SPVM::Example->INFINITY())) {
      if (!SPVM::Example->isfinite(SPVM::Example->NAN())) {
        if (SPVM::Example->isfinite(0.1)) {
          return 1;
        }
      }
    }
    
    return 0;
  }

  sub isnan : int () {
    if (!SPVM::Example->isnan(SPVM::Example->INFINITY())) {
      if (SPVM::Example->isnan(SPVM::Example->NAN())) {
        if (!SPVM::Example->isnan(0.1)) {
          return 1;
        }
      }
    }
    
    return 0;
  }
  
  sub double_pass_nan : int ($value : double) {
    if (SPVM::Example->isnan($value)) {
      return 1;
    }
    
    return 0;
  }
  
  sub double_pass_positive_infinity : int ($value : double) {
    if ($value == SPVM::Example->INFINITY()) {
      return 1;
    }
    
    return 0;
  }

  sub byte_constant : int () {
    if ((int)SPVM::Example->INT8_MIN() == (int)(byte)-128) {
      if ((int)SPVM::Example->INT8_MAX() == (int)(byte)127) {
        return 1;
      }
    }
    
    return 0;
  }

  sub short_constant : int () {
    if ((int)SPVM::Example->INT16_MIN() == (int)(short)-32768) {
      if ((int)SPVM::Example->INT16_MAX() == (int)(short)32767) {
        return 1;
      }
    }
    
    return 0;
  }

  sub int_constant : int () {
    if (SPVM::Example->INT32_MIN() == -2147483648) {
      if (SPVM::Example->INT32_MAX() == 2147483647) {
        return 1;
      }
    }
    
    return 0;
  }

  sub long_constant : int () {
    if (SPVM::Example->INT64_MIN() == -9223372036854775808L) {
      if (SPVM::Example->INT64_MAX() == 9223372036854775807L) {
        return 1;
      }
    }
    
    return 0;
  }
}
