/*
   Copyright (C) 2013  Statoil ASA, Norway. 
    
   The file 'ecl_sum_test.c' is part of ERT - Ensemble based Reservoir Tool. 
    
   ERT is free software: you can redistribute it and/or modify 
   it under the terms of the GNU General Public License as published by 
   the Free Software Foundation, either version 3 of the License, or 
   (at your option) any later version. 
    
   ERT is distributed in the hope that it will be useful, but WITHOUT ANY 
   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
   FITNESS FOR A PARTICULAR PURPOSE.   
    
   See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> 
   for more details. 
*/
#include <stdlib.h>
#include <stdbool.h>

#include <ert/util/test_util.h>
#include <ert/util/time_t_vector.h>
#include <ert/util/util.h>

#include <ert/ecl/ecl_sum.h>


void test_time_range( const ecl_sum_type * ecl_sum ) {
  // Hardcoded Gurbat case values
  time_t start = util_make_date( 1,1,2000);
  time_t end   = util_make_date( 31,12,2004 );

  test_assert_time_t_equal( ecl_sum_get_start_time( ecl_sum ) , start );
  test_assert_time_t_equal( ecl_sum_get_end_time( ecl_sum )   , end );
  test_assert_time_t_equal( ecl_sum_get_data_start(ecl_sum) , start);
}


void test_days( const ecl_sum_type * ecl_sum ) {
  time_t date1  = util_make_date( 1,1,2000);
  time_t date2  = util_make_date( 31,12,2004 );
  time_t date3  = util_make_date( 2,1,2000 );

  double days1 = ecl_sum_time2days( ecl_sum , date1 );
  double days2 = ecl_sum_time2days( ecl_sum , date2);
  double days3 = ecl_sum_time2days( ecl_sum , date3 );

  test_assert_double_equal( days1 , 0 );
  test_assert_double_equal( days2 , 1826 );
  test_assert_double_equal( days3 , 1 );
}





int main( int argc , char ** argv) {
  const char * casename = argv[1];

  ecl_sum_type * ecl_sum = ecl_sum_fread_alloc_case( casename , ":");

  test_time_range( ecl_sum );
  test_days( ecl_sum );

  exit(0);
}
