Beispiel #1
0
void test_score_sequence(void) {
  char *seqa = "ATCGATCGATCGATCGATCGATCG";
  char *seqb = "AACGATCGATCGATCGATCGATCG";
  int cmp1[] = {1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  int *cmp1_t = score_sequence(seqa, seqb, strlen(seqa));

  TEST_INIT;
  TEST_ARRAY(cmp1, cmp1_t, 24, "score_sequence");

  TEST(sum(score_sequence(seqa, seqb, strlen(seqa)), strlen(seqa)) == 22, "sum of score_sequence");

  TEST_CLOSE;
}
Beispiel #2
0
int main()
{
    //fast access
    using program_language = l_language::l_vm;
    using compiler_flags   = l_language::l_vm::compiler_flags;
    //source file
    std::string i_source        = "scripts/function.ll";
    int         f_compier_flags = compiler_flags::EXECUTE;
    //compiler object
    program_language it_compiler;
    //add libs
    it_compiler.add_lib(l_language::l_base_lib);
    it_compiler.add_lib("io", l_language::l_io_lib);
    it_compiler.add_lib("os", l_language::l_os_lib);
    //read code // "source.it"
    std::ifstream source_file(i_source);
    std::string source((std::istreambuf_iterator<char>(source_file)),
                       (std::istreambuf_iterator<char>()));
    //compile
    program_language::compiler_ouput compiler_ouput;
    compiler_ouput = it_compiler.compile(source,f_compier_flags);
    //ouput:
    if(compiler_ouput.m_type & program_language::ERRORS)
    {
        std::cout << compiler_ouput.m_errors;
        return -1;
    }
    //tests
    TEST("pow2",  // test name
          pow2,   // function
          36.0f,  // return
          6.0f    // args
         );
    
    TEST("diff",       // test name
          diff,        // function
          1.0f,        // return
          2.0f, 1.0f   // args
         );
    
    TEST("fib",      // test name
          fib,        // function
          89.0f,      // return
          10.0f       // args
         );
    
    TEST("super",      // test name
         super_test,   // function
         5.0f,         // return
         0.0f          // args
         );
    
    TEST("for of",      // test name
         for_of_test,   // function
         15.0f,         // return
         0.0f           // args
         );
    
    
    TEST("for in",      // test name
         for_in_test,   // function
         10.0f,         // return
         0.0f           // args
         );
    
    TEST_TYPE_OF("is int",   // test name
                 int_test,   // function
                 INT,        // return type
                 0           // args
                 );
    
    TEST_TYPE_OF("is float",   // test name
                 float_test,   // function
                 FLOAT,        // return type
                 0             // args
                 );
    TEST_TYPE_OF("is string",  // test name
                 string_test,  // function
                 STRING,       // return type
                 0             // args
                 );
    
    std::vector<l_language::l_variable> array_test_values =
    {
        1.2f,
        3,
        l_language::l_string::const_new(it_compiler.get_gc(), "hello"),
        l_language::l_string::const_new(it_compiler.get_gc(), "l"),
        l_language::l_string::const_new(it_compiler.get_gc(), "language")
    };
    
    TEST_ARRAY("generic test array",  // test name
               array_test,            // function
               array_test_values,     // return
               0                      // args
               );
    
    //1-100
    int range_values = rand() % 100 + 1;
    
    TEST("for range(len) rand",    // test name
         for_range_1_rand,         // function
         gauss(range_values-1),    // return
         range_values              // args
         );
    
    TEST("for like c rand",        // test name
         for_c_like,               // function
         90,                       // return
         0                         // args
         );

    
    //0-(range_values-1)
    int start_values = rand() % range_values - 1 ;
    
    TEST("for range(start,len) rand",                    // test name
         for_range_2_rand,                               // function
         gauss(range_values-1)-gauss(start_values),      // return
         start_values,range_values                       // args
         );
    
    std::vector<l_language::l_variable> array_range_values =
    {
        1,
        3
    };
    
    TEST_ARRAY("range(start,len,step)",  // test name
         range_3,                        // function
         array_range_values,             // return
         1,5,2                           // args
         );
    
    //lambda calc test
    int rand_l_c_1 = rand() % 100 - 1 ;
    
    TEST("lambda calc 1",   // test name
          lambda_calc_1,    // function
          rand_l_c_1,       // return
          rand_l_c_1        // args
         );
    
    int rand_l_2_n   = rand() % 100 - 1 ;
    int rand_l_2_c   = rand() % 100 - 1 ;
    int rand_l_2_d   = rand() % 100 - 1 ;
    int rand_l_2_ret = rand_l_2_n*(rand_l_2_c+rand_l_2_d);
    
    TEST("lambda calc 2",                   // test name
         lambda_calc_2,                     // function
         rand_l_2_ret,                      // return
         rand_l_2_n, rand_l_2_c, rand_l_2_d // args
         );
    
    TEST("lambda calc fib",  // test name
         lambda_calc_fib,    // function
         89.0f,              // return
         10.0f               // args
         );
    //print success
    std::cout << s_count_success << " of " << s_count_test << " successes" << std::endl;
    //print fails
    if(s_tests_fails.size())
        for(const std::string& test_name : s_tests_fails)
            std::cout << "- failed \"" << test_name << "\" test" << std::endl;
}