Exemple #1
0
int main()
{
  printf ("Results of any_test:\n");
  
  try
  {  
    printf                 ("default construction\n");
    test_default_ctor      ();
    printf                 ("single argument construction\n");
    test_converting_ctor   ();
    printf                 ("copy construction\n");
    test_copy_ctor         ();
    printf                 ("copy assignment operator\n");
    test_copy_assign       ();
    printf                 ("converting assignment operator\n");
    test_converting_assign ();
    printf                 ("failed custom keyword cast\n");
    test_bad_cast          ();
    printf                 ("swap member function\n");
    test_swap              ();
    printf                 ("copying operations on a null\n");
    test_null_copying      ();
  }
  catch (std::exception& exception)
  {
    printf ("fail with exception: %s\n", exception.what ());
  }

  return 0;
}
void test_generic_multiset<ValueTraits, ContainerDefiner>::test_all ()
{
   typedef typename ValueTraits::value_type value_type;
   static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
   value_cont_type values (6);
   for (int i = 0; i < 6; ++i)
      (&values[i])->value_ = random_init[i];
   typedef ContainerDefiner
      < value_type
      , value_traits<ValueTraits>
      , constant_time_size<value_type::constant_time_size>
      > definer_function;
   typedef typename definer_function::type multiset_type;
   {
      multiset_type testset(values.begin(), values.end());
      test::test_container(testset);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_common_unordered_and_associative_container(testset, values);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_associative_container(testset, values);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_non_unique_container(testset, values);
   }
   test_sort(values);
   test_insert(values);
   test_swap(values);
   test_find(values);
   test_impl();
   test_generic_assoc<ValueTraits, ContainerDefiner>::test_all(values);
}
void test_generic_set<ValueTraits, ContainerDefiner>::test_all()
{
   typedef typename ValueTraits::value_type value_type;
   static const int random_init[6] = { 3, 2, 4, 1, 5, 2 };
   std::vector<value_type> values (6);
   for (int i = 0; i < 6; ++i)
      values[i].value_ = random_init[i];

   typedef typename ContainerDefiner
      < value_type
      , value_traits<ValueTraits>
      , constant_time_size<value_type::constant_time_size>
      >::type set_type;
   {
      set_type testset(values.begin(), values.end());
      test::test_container(testset);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_common_unordered_and_associative_container(testset, values);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_associative_container(testset, values);
      testset.clear();
      testset.insert(values.begin(), values.end());
      test::test_unique_container(testset, values);
   }
   test_sort(values);
   test_insert(values);
   test_insert_advanced(values);
   test_swap(values);
   test_find(values);
   test_impl();
   test_generic_assoc<ValueTraits, ContainerDefiner>::test_all(values);
}
Exemple #4
0
int main()
{
  matrix_construction();
  matrix_access();
  test_cblas_dgemm();
  test_basic_alloc();
  test_asum();
  test_axpy();
  test_copy();
  test_dot();
  test_sdot();
  test_dotc();
  test_dotu();
  test_nrm2();
  test_rot();
  test_rotg();
  test_scal();
  test_swap();
  test_iamax();
  test_iamin();
  test_dcabs1();
  test_gemv();
  test_gemm();
  test_vmul();
  test_vml();
  test_std_vector_vml();
  test_gemm_boost();
  return 0;
}
Exemple #5
0
int main() {
    test_swap();
    test_InsertionSort();
    test_MergeSort();
    test_BubbleSort();
    test_SelectionSort();
    return 0;
}
Exemple #6
0
int
main()
{
    /* same-size is easier to handle */
    test_swap(16*1024, 16*1024);
    /* this one is more difficult since if base threshold on 1st malloc size
     * will get unaddr on swapping to smaller higher stack
     */
    test_swap(32*1024, 24*1024);
    /* test giant alloca (will also test fault on special shadow write) */
    test_alloca();
    /* i#668 test esp adjusted by cmovcc */
    stack1 = (char *) malloc(16*1024) + 16*1024;
    test_cmovcc_asm();
    free((char *)stack1 - 16*1024);
    printf("all done\n");
    return 0;
}
Exemple #7
0
void test_swap (T*, Allocator*,
                const ContainerTestCaseData<T> &tdata)
{
    if (Swap (cont_cont) == tdata.func_.which_) {

        test_std_swap ();

        return;
    }

    SharedAlloc sa1;
    Allocator a1 = make_alloc(sa1, (Allocator*)0);

    // test swap using the same allocator objects
    test_swap ((T*)0, a1, a1, tdata);

    SharedAlloc sa2;
    Allocator a2 = make_alloc(sa2, (Allocator*)0);

    if (a1 != a2) {
        // test swap using different allocator objects
        test_swap ((T*)0, a1, a2, tdata);
    }
}
Exemple #8
0
static void test_swap(skiatest::Reporter* reporter) {
    int sizes[] = {0, 1, 5, 10, 15, 20, 25};

    SkTArray<int> arr;
    SkSTArray< 5, int> arr5;
    SkSTArray<10, int> arr10;
    SkSTArray<20, int> arr20;
    SkTArray<int>* arrays[] = { &arr, &arr5, &arr10, &arr20 };
    test_swap(reporter, arrays, sizes);

    struct MoveOnlyInt {
        MoveOnlyInt(int i) : fInt(i) {}
        MoveOnlyInt(MoveOnlyInt&& that) : fInt(that.fInt) {}
        bool operator==(int i) { return fInt == i; }
        int fInt;
    };

    SkTArray<MoveOnlyInt> moi;
    SkSTArray< 5, MoveOnlyInt> moi5;
    SkSTArray<10, MoveOnlyInt> moi10;
    SkSTArray<20, MoveOnlyInt> moi20;
    SkTArray<MoveOnlyInt>* arraysMoi[] = { &moi, &moi5, &moi10, &moi20 };
    test_swap(reporter, arraysMoi, sizes);
}
void test_swap (const T*, const char* tname)
{
    rw_info (0, 0, 0, 
             "std::deque<%s>::swap(deque<%1$s>&)", tname);

    typedef std::deque<T, std::allocator<T> > MyDeque;
    typedef typename MyDeque::iterator        Iterator;

    // create two empty deque objects
    MyDeque empty [2];

    // save their begin and end iterators before calling swap
    const Iterator before [2][2] = {
        { empty [0].begin (), empty [0].end () },
        { empty [1].begin (), empty [1].end () }
    };

    // swap the two containers
    empty [0].swap (empty [1]);

    // get the new begin and end iterators
    const Iterator after [2][2] = {
        { empty [0].begin (), empty [0].end () },
        { empty [1].begin (), empty [1].end () }
    };

    // verify that the iterators have not been invalidated
    rw_assert (   before [0][0] == after [1][0] 
               && before [1][0] == after [0][0], 0, __LINE__, 
               "deque<%s>().begin() not swapped", tname);
    
    rw_assert (   before [0][1] == after [1][1] 
               && before [1][1] == after [0][1], 0, __LINE__, 
               "deque<%s>().end() not swapped", tname);

    // static to zero-initialize if T is a POD type
    static T seq [32];

    const std::size_t seq_len = sizeof seq / sizeof *seq;

    for (std::size_t i = 0; i != seq_len; ++i) {
        for (std::size_t j = 0; j != seq_len; ++j) {
            test_swap (seq, i, seq, j, (MyDeque*)0, tname);
        }
    }
}
Exemple #10
0
int main()
{
	Test* test =new Test();
	test_creating_empty_list(test);
	test_creating_full_list(test);
	test_front(test);
	test_push_front(test);
	test_push_back(test);
	test_pop_front(test);
	test_pop_back(test);
	test_iter(test);
	test_reverse(test);
	test_swap(test);
	test_input(test);	
	test_cp(test);
	test_const_iter(test);
}
Exemple #11
0
int run_test (int, char**)
{
    // Test std::swap calling std::deque::swap
    test_std_swap ();

    static const Deque::size_type caps[] = {
        2, 3, 4, 5, 16, 32
    };

    for (std::size_t i = 0; i != sizeof caps / sizeof *caps; ++i) {

        new_capacity = caps [i];

        rw_info (0, 0, 0, 
                 "__rw::__rw_new_capacity<std::deque<UserClass> >(0) = %u",
                 _RW::__rw_new_capacity (0, (Deque*)0));

        test_swap ();
    }

    return 0;
}
Exemple #12
0
DEF_TEST(TArray, reporter) {
    TestTSet_basic<true>(reporter);
    TestTSet_basic<false>(reporter);
    test_swap(reporter);

    test_copy_ctor(reporter, SkTArray<sk_sp<SkRefCnt>, false>());
    test_copy_ctor(reporter, SkTArray<sk_sp<SkRefCnt>,  true>());
    test_copy_ctor(reporter, SkSTArray< 1, sk_sp<SkRefCnt>, false>());
    test_copy_ctor(reporter, SkSTArray< 1, sk_sp<SkRefCnt>,  true>());
    test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>, false>());
    test_copy_ctor(reporter, SkSTArray<10, sk_sp<SkRefCnt>,  true>());

    test_move(reporter);

    test_unnecessary_alloc(reporter);

    test_self_assignment(reporter);

    test_reserve<SkTArray<int>>(reporter);
    test_reserve<SkSTArray<1, int>>(reporter);
    test_reserve<SkSTArray<2, int>>(reporter);
    test_reserve<SkSTArray<16, int>>(reporter);
}
Exemple #13
0
static int	put_raw
(
    pfi		char_out,
    int		a[],
    int		nx,
    int		ny,
    boolean	swap 
)
{
    void	h_swap_bytes();
    boolean	test_swap();

    int		i;
    int		j;
    int		k;
    short	*sa;		/* Working array for swaped data.	*/
    boolean	tswap;		/* is byte swaping required?		*/
    int		v;


    /*
     * see if byte-swapping will be needed
     */

    if (swap) 
    {
	tswap = test_swap();
    } 
    else 
    {
	tswap = 0;
    }


    /*
     * write a row at a time to minimize page faulting problems
     */

    PR_CHECK_NULL( sa = short_alloc( ny ) );

    for ( i = 0; i < nx ; i++ ) 
    {
	k = i * ny;

	for ( j = 0; j < ny; j++) 
	{
	    /*
	     * force value into 16-bit integer range
	     */

	    v = a[k++];
	    if (v < -32768) 
	    {
		sa[j] = -32768;
	    } 
	    else if (v > 32767) 
	    {
		sa[j] = 32767;
	    } 
	    else 
	    {
		sa[j] = v;
	    }
	}

	if ( tswap ) 
	{
	    h_swap_bytes( sa, ny * sizeof( short ) );
	}
	PR_CHECK( char_out( sa, ny * sizeof( short ) ) );
    }
    gen_free(sa);

    return( PR_SUCCESS );
}
Exemple #14
0
void test_swap ()
{
    test_swap ((int*)0, "int");
    test_swap ((UserClass*)0, "UserClass");
}
main()
{
  int i = 5;
  int j = 7;
  test_swap(i, j);
}
Exemple #16
0
int main() {
  test_construction();
  test_insertion_erasure_and_searching();
  test_swap();
  std::cout << "OK\n";
}
DEF_TEST(TArray, reporter) {
    TestTSet_basic<true>(reporter);
    TestTSet_basic<false>(reporter);
    test_swap(reporter);
}
Exemple #18
0
int main(int argc, char *argv[])
{
    int ans;
    char *str, *strout;
    
    fmpz_poly_t zpoly;
    fmpz_poly_q_t qpoly1;
    
    mpz_t mpzzero, mpzone, mpztwo;
    mpq_t mpqzero, mpqone, mpqtwo, mpqtwoinv;
    
    FLINT_TEST_INIT(state);
    
    flint_printf("all... ");
    fflush(stdout);
    
    /* Accessing numerator and denominator ***********************************/
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_q_set_str(qpoly1, "2  -1 1/2  0 1");
    str = "2  -1 1";
    strout = fmpz_poly_get_str(fmpz_poly_q_numref(qpoly1));
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_numref: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        flint_printf("    qpoly1 = \""), fmpz_poly_q_print(qpoly1), flint_printf("\"\n");
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_q_set_str(qpoly1, "2  -1 1/2  0 1");
    str = "2  0 1";
    strout = fmpz_poly_get_str(fmpz_poly_q_denref(qpoly1));
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_denref: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_init(zpoly);
    fmpz_poly_q_set_str(qpoly1, "2  -1 1/2  0 1");
    fmpz_poly_set(zpoly, fmpz_poly_q_numref(qpoly1));
    str = "2  -1 1";
    strout = fmpz_poly_get_str(zpoly);
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_get_num: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    fmpz_poly_clear(zpoly);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_init(zpoly);
    fmpz_poly_q_set_str(qpoly1, "2  -1 1/2  0 1");
    fmpz_poly_set(zpoly, fmpz_poly_q_denref(qpoly1));
    
    str = "2  0 1";
    strout = fmpz_poly_get_str(zpoly);
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_get_den: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    fmpz_poly_clear(zpoly);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_init(zpoly);
    fmpz_poly_q_set_str(qpoly1, "1  1/1  1");
    fmpz_poly_set_str(zpoly, "2  0 1");
    fmpz_poly_set(fmpz_poly_q_numref(qpoly1), zpoly);
    str = "2  0 1";
    strout = fmpz_poly_get_str(fmpz_poly_q_numref(qpoly1));
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_set_num: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    fmpz_poly_clear(zpoly);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    fmpz_poly_init(zpoly);
    fmpz_poly_q_set_str(qpoly1, "1  1/1  1");
    fmpz_poly_set_str(zpoly, "2  0 1");
    fmpz_poly_set(fmpz_poly_q_denref(qpoly1), zpoly);
    str = "2  0 1";
    strout = fmpz_poly_get_str(fmpz_poly_q_denref(qpoly1));
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_set_den: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    fmpz_poly_clear(zpoly);
    flint_free(strout);
    
    /* Canonicalise **********************************************************/
    
    fmpz_poly_q_init(qpoly1);
    str = "2  -1 1/2  0 1";
    fmpz_poly_q_set_str(qpoly1, str);
    strout = fmpz_poly_q_get_str(qpoly1);
    ans = !strcmp(str, strout);
    if (!ans)
    {
        flint_printf("test_canonicalize: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    flint_free(strout);
    
    fmpz_poly_q_init(qpoly1);
    str = "2  -1 -1/2  0 1";
    fmpz_poly_q_set_str(qpoly1, "2  1 1/2  0 -1");
    strout = fmpz_poly_q_get_str(qpoly1);
    ans = !strcmp("2  -1 -1/2  0 1", strout);
    if (!ans)
    {
        flint_printf("test_canonicalize: failed\n");
        flint_printf("    Expected \"%s\", got \"%s\"\n", str, strout);
        abort();
    }
    flint_free(strout);
    fmpz_poly_q_clear(qpoly1);
    
    /* Initialization, memory management and basic operations ****************/
    
    test_set("0", "0");
    test_set("0/1  1", "0");
    test_set("3  -1 0 1/2  0 1", "3  -1 0 1/2  0 1");
    test_set("3  -1 0 1/2  1 1", "2  -1 1");
    
    test_set_si(-1, "1  -1");
    test_set_si(13, "1  13");
    test_set_si(0, "0");
    
    test_swap("3  -1 0 1/2  0 1", "1  2/1  3", "1  2/1  3", "3  -1 0 1/2  0 1");
    
    test_zero("0", "0");
    test_zero("0/1  1", "0");
    test_zero("3  -1 0 1/2  0 1", "0");
    
    test_neg("0", "0");
    test_neg("1  1/1  2", "1  -1/1  2");
    test_neg("3  -1 0 1/2  0 1", "3  1 0 -1/2  0 1");
    
    test_inv("1  1/1  2", "1  2");
    test_inv("3  -1 0 1/2  0 1", "2  0 1/3  -1 0 1");
    test_inv("3  -1 0 -1/2  0 1", "2  0 -1/3  1 0 1");
    
    test_inv_inplace("1  1/1  2", "1  2");
    test_inv_inplace("3  -1 0 1/2  0 1", "2  0 1/3  -1 0 1");
    test_inv_inplace("3  -1 0 -1/2  0 1", "2  0 -1/3  1 0 1");
    
    test_is_zero("0", 1);
    test_is_zero("0/1  1", 1);
    test_is_zero("3  -1 0 1/2  0 1", 0);
    test_is_zero("3  -1 0 1/2  1 1", 0);
    
    test_is_one("0", 0);
    test_is_one("0/1  1", 0);
    test_is_one("1  1/1  1", 1);
    test_is_one("2  1 1/2  1 1", 1);
    test_is_one("3  -1 0 1/2  0 1", 0);
    
    test_equal("1  1/1  2", "1  1/1  2", 1);
    test_equal("1  1/1  2", "1  1/1  2", 1);
    test_equal("3  -1 0 1/2  1 1", "2  -1 1", 1);
    test_equal("3  -1 0 1/2  -1 1", "2  -1 1", 0);
    
    /* Addition and subtraction **********************************************/
    
    test_add("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 1 0 1/4  0 1 0 1");
    test_add("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  3 -2 1/2  -1 1");
    test_add("0/2  1 1", "1  2/1  1", "1  2");
    test_add("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_add("2  1 1/1  1", "2  -1 1/1  1", "2  0 2");
    test_add("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  -1 2 2/3  0 -1 1");
    test_add("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  7 12 7 1/3  2 3 1");
    test_add("2  1 1/2  -1 1", "2  1 1", "3  0 1 1/2  -1 1");
    test_add("1  1/2  1 1", "2  0 1/2  1 1", "1  1");
    test_add("2  1 1/3  4 -4 1", "1  1/2  -2 1", "2  -1 2/3  4 -4 1");
    test_add("3  0 1 1/3  1 2 1", "2  0 -1/2  1 1", "0");
    test_add("2  1 1/2  0 1", "2  -1 1/2  0 1", "1  2");
    test_add("1  1/3  3 5 2", "1  1/3  6 7 2", "1  1/3  2 3 1");
    
    test_add_in_place1("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 1 0 1/4  0 1 0 1");
    test_add_in_place1("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  3 -2 1/2  -1 1");
    test_add_in_place1("0/2  1 1", "1  2/1  1", "1  2");
    test_add_in_place1("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_add_in_place1("2  1 1/1  1", "2  -1 1/1  1", "2  0 2");
    test_add_in_place1("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  -1 2 2/3  0 -1 1");
    test_add_in_place1("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  7 12 7 1/3  2 3 1");
    test_add_in_place1("2  1 1/2  -1 1", "2  1 1", "3  0 1 1/2  -1 1");
    test_add_in_place1("1  1/2  1 1", "2  0 1/2  1 1", "1  1");
    test_add_in_place1("2  1 1/3  4 -4 1", "1  1/2  -2 1", "2  -1 2/3  4 -4 1");
    test_add_in_place1("3  0 1 1/3  1 2 1", "2  0 -1/2  1 1", "0");
    test_add_in_place1("2  1 1/2  0 1", "2  -1 1/2  0 1", "1  2");
    
    test_add_in_place2("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 1 0 1/4  0 1 0 1");
    test_add_in_place2("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  3 -2 1/2  -1 1");
    test_add_in_place2("0/2  1 1", "1  2/1  1", "1  2");
    test_add_in_place2("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_add_in_place2("2  1 1/1  1", "2  -1 1/1  1", "2  0 2");
    test_add_in_place2("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  -1 2 2/3  0 -1 1");
    test_add_in_place2("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  7 12 7 1/3  2 3 1");
    test_add_in_place2("2  1 1/2  -1 1", "2  1 1", "3  0 1 1/2  -1 1");
    test_add_in_place2("1  1/2  1 1", "2  0 1/2  1 1", "1  1");
    test_add_in_place2("2  1 1/3  4 -4 1", "1  1/2  -2 1", "2  -1 2/3  4 -4 1");
    test_add_in_place2("3  0 1 1/3  1 2 1", "2  0 -1/2  1 1", "0");
    test_add_in_place2("2  1 1/2  0 1", "2  -1 1/2  0 1", "1  2");
    
    test_add_in_place3("2  1 1", "2  2 2");
    test_add_in_place3("2  1 1/1  2", "2  1 1");
    
    test_sub("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 3 0 1/4  0 1 0 1");
    test_sub("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  -1 -2 1/2  -1 1");
    test_sub("0/2  1 1", "1  2/1  1", "1  -2");
    test_sub("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_sub("2  1 1/1  1", "2  -1 1/1  1", "1  2");
    test_sub("2  1 1/2  0 1", "2  2 1/2  -1 1", "2  -1 -2/3  0 -1 1");
    test_sub("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  -9 -12 -5 -1/3  2 3 1");
    test_sub("2  -1 1/2  0 1", "1  1", "1  -1/2  0 1");
    test_sub("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 3 0 1/4  0 1 0 1");
    test_sub("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  -1 -2 1/2  -1 1");
    test_sub("0/2  1 1", "1  2/1  1", "1  -2");
    test_sub("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_sub("2  1 1/1  1", "2  -1 1/1  1", "1  2");
    test_sub("2  1 1/2  0 1", "2  2 1/2  -1 1", "2  -1 -2/3  0 -1 1");
    test_sub("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  -9 -12 -5 -1/3  2 3 1");
    test_sub("2  1 1/2  -1 1", "2  1 1", "3  2 1 -1/2  -1 1");
    test_sub("1  1/2  1 1", "2  0 1/2  1 1", "2  1 -1/2  1 1");
    test_sub("2  1 1/3  4 -4 1", "1  1/2  -2 1", "1  3/3  4 -4 1");
    test_sub("3  0 1 1/3  1 2 1", "2  0 -1/2  1 1", "2  0 2/2  1 1");
    test_sub("2  1 1/2  0 1", "2  -1 1/2  0 1", "1  2/2  0 1");
    test_sub("1  1/3  3 5 2", "1  1/3  6 7 2", "1  1/4  6 13 9 2");
    test_sub("2  1 1/2  0 2", "2  1 1/2  0 2", "0");
    test_sub("2  -1 2/2  0 1", "2  -1 1/2  0 1", "1  1");
    
    test_sub_in_place1("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 3 0 1/4  0 1 0 1");
    test_sub_in_place1("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  -1 -2 1/2  -1 1");
    test_sub_in_place1("0/2  1 1", "1  2/1  1", "1  -2");
    test_sub_in_place1("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_sub_in_place1("2  1 1/1  1", "2  -1 1/1  1", "1  2");
    test_sub_in_place1("2  1 1/2  0 1", "2  2 1/2  -1 1", "2  -1 -2/3  0 -1 1");
    test_sub_in_place1("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  -9 -12 -5 -1/3  2 3 1");
    
    test_sub_in_place2("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "5  1 0 3 0 1/4  0 1 0 1");
    test_sub_in_place2("3  -1 0 1/2  1 1", "1  2/2  -1 1", "3  -1 -2 1/2  -1 1");
    test_sub_in_place2("0/2  1 1", "1  2/1  1", "1  -2");
    test_sub_in_place2("1  -3/1  4", "0/3  1 0 1", "1  -3/1  4");
    test_sub_in_place2("2  1 1/1  1", "2  -1 1/1  1", "1  2");
    test_sub_in_place2("2  1 1/2  0 1", "2  2 1/2  -1 1", "2  -1 -2/3  0 -1 1");
    test_sub_in_place2("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "4  -9 -12 -5 -1/3  2 3 1");
    
    test_sub_in_place3("2  -1 1/2  2 1", "0");
    
    test_addmul("1  1/2  0 2", "2  3 1/1  4", "3  1 0 1/4  -2 0 0 1", "5  -4 3 1 5 1/5  0 -8 0 0 4");
    
    test_submul("1  1/2  0 2", "2  3 1/1  4", "3  1 0 1/4  -2 0 0 1", "5  -4 -3 -1 -1 -1/5  0 -8 0 0 4");
    
    /* Scalar multiplication and devision ************************************/
    
    flint_mpz_init_set_si(mpzzero, 0);
    flint_mpz_init_set_si(mpzone, 1);
    flint_mpz_init_set_si(mpztwo, 2);
    
    mpq_init(mpqzero); flint_mpq_set_si(mpqzero, 0, 1);
    mpq_init(mpqone); flint_mpq_set_si(mpqone, 1, 1);
    mpq_init(mpqtwo); flint_mpq_set_si(mpqtwo, 2, 1);
    mpq_init(mpqtwoinv); flint_mpq_set_si(mpqtwoinv, 1, 2);
    
    test_scalar_mul_si("0", 1, "0");
    test_scalar_mul_si("0", 0, "0");
    test_scalar_mul_si("1  2", 0, "0");
    test_scalar_mul_si("1  1/1  2", -2, "1  -1");
    test_scalar_mul_si("2  1 1/2  -2 3", 5, "2  5 5/2  -2 3");
    test_scalar_mul_si("2  1 1/2  -2 2", 3, "2  3 3/2  -2 2");
    
    test_scalar_mul_mpz("0", mpzone, "0");
    test_scalar_mul_mpz("0", mpzzero, "0");
    test_scalar_mul_mpz("1  2", mpzzero, "0");
    test_scalar_mul_mpz("1  1/1  2", mpztwo, "1  1");
    
    test_scalar_mul_mpq("0", mpqone, "0");
    test_scalar_mul_mpq("0", mpqzero, "0");
    test_scalar_mul_mpq("1  2", mpqzero, "0");
    test_scalar_mul_mpq("1  1/1  2", mpqtwo, "1  1");
    test_scalar_mul_mpq("1  -2/1  1", mpqtwoinv, "1  -1");
    
    test_scalar_div_si("0", 1, "0");
    test_scalar_div_si("1  2", 2, "1  1");
    test_scalar_div_si("1  1/1  2", -2, "1  -1/1  4");
    test_scalar_div_si("3  -5 0 3/2  1 1", 2, "3  -5 0 3/2  2 2");
    test_scalar_div_si("3  2 8 4/2  0 1", 3, "3  2 8 4/2  0 3");
    test_scalar_div_si("3  2 8 4/2  0 1", -3, "3  -2 -8 -4/2  0 3");
    test_scalar_div_si("3  -27 0 9/2  0 1", -3, "3  9 0 -3/2  0 1");
    
    test_scalar_div_mpz("0", mpzone, "0");
    test_scalar_div_mpz("1  2", mpztwo, "1  1");
    test_scalar_div_mpz("1  1/1  2", mpztwo, "1  1/1  4");
    
    test_scalar_div_mpq("0", mpqone, "0");
    test_scalar_div_mpq("1  2", mpqone, "1  2");
    test_scalar_div_mpq("1  1/1  2", mpqtwo, "1  1/1  4");
    test_scalar_div_mpq("1  -2/1  1", mpqtwoinv, "1  -4");
    
    mpz_clear(mpzzero);
    mpz_clear(mpzone);
    mpz_clear(mpztwo);
    mpq_clear(mpqzero);
    mpq_clear(mpqone);
    mpq_clear(mpqtwo);
    mpq_clear(mpqtwoinv);
    
    /* Multiplication, division and powing *********************************/
    
    test_mul("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "1  -1");
    test_mul("3  -1 0 1/2  1 1", "1  2/2  -1 1", "1  2");
    test_mul("0/2  1 1", "1  2/1  1", "0");
    test_mul("1  -3/1  4", "0/3  1 0 1", "0");
    test_mul("2  1 1/1  1", "2  -1 1/1  1", "3  -1 0 1");
    test_mul("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  2 3 1/3  0 -1 1");
    test_mul("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "3  -2 1 1/2  1 1");
    
    test_mul_in_place1("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "1  -1");
    test_mul_in_place1("3  -1 0 1/2  1 1", "1  2/2  -1 1", "1  2");
    test_mul_in_place1("0/2  1 1", "1  2/1  1", "0");
    test_mul_in_place1("1  -3/1  4", "0/3  1 0 1", "0");
    test_mul_in_place1("2  1 1/1  1", "2  -1 1/1  1", "3  -1 0 1");
    test_mul_in_place1("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  2 3 1/3  0 -1 1");
    test_mul_in_place1("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "3  -2 1 1/2  1 1");
    
    test_mul_in_place2("3  1 0 1/2  0 1", "2  0 -1/3  1 0 1", "1  -1");
    test_mul_in_place2("3  -1 0 1/2  1 1", "1  2/2  -1 1", "1  2");
    test_mul_in_place2("0/2  1 1", "1  2/1  1", "0");
    test_mul_in_place2("1  -3/1  4", "0/3  1 0 1", "0");
    test_mul_in_place2("2  1 1/1  1", "2  -1 1/1  1", "3  -1 0 1");
    test_mul_in_place2("2  1 1/2  0 1", "2  2 1/2  -1 1", "3  2 3 1/3  0 -1 1");
    test_mul_in_place2("2  -1 1/2  2 1", "3  4 4 1/2  1 1", "3  -2 1 1/2  1 1");
    
    test_mul_in_place3("2  0 1/2  1 1", "3  0 0 1/3  1 2 1");
    
    test_div("3  -1 0 1/1  2", "2  1 1/1  1", "2  -1 1/1  2");
    test_div("0/2  1 1", "2  1 1/1  1", "0");
    test_div("3  -1 0 1/1  4", "2  -1 -1/1  2", "2  1 -1/1  2");
    test_div("2  1 1", "2  1 -1/2  1 -1", "2  1 1");
    test_div("2  1 1/3  4 4 1", "2  -1 1/3  6 5 1", "3  3 4 1/3  -2 1 1");
    
    test_div_in_place1("3  -1 0 1/1  2", "2  1 1/1  1", "2  -1 1/1  2");
    test_div_in_place1("0/2  1 1", "2  1 1/1  1", "0");
    test_div_in_place1("3  -1 0 1/1  4", "2  -1 -1/1  2", "2  1 -1/1  2");
    test_div_in_place1("2  1 1", "2  1 -1/2  1 -1", "2  1 1");
    test_div_in_place1("2  1 1/3  4 4 1", "2  -1 1/3  6 5 1", "3  3 4 1/3  -2 1 1");
    test_div_in_place1("0", "1  2/2  3 5", "0");
    
    test_div_in_place2("3  -1 0 1/1  2", "2  1 1/1  1", "2  -1 1/1  2");
    test_div_in_place2("0/2  1 1", "2  1 1/1  1", "0");
    test_div_in_place2("3  -1 0 1/1  4", "2  -1 -1/1  2", "2  1 -1/1  2");
    test_div_in_place2("2  1 1", "2  1 -1/2  1 -1", "2  1 1");
    test_div_in_place2("2  1 1/3  4 4 1", "2  -1 1/3  6 5 1", "3  3 4 1/3  -2 1 1");
    
    test_div_in_place3("3  -1 0 1/1  2", "1  1");
    
    test_pow("2  0 -1/1  2", 3, "4  0 0 0 -1/1  8");
    test_pow("0", 0, "1  1");
    test_pow("2  1 -1", 0, "1  1");
    test_pow("2  1 1/2  0 1", 0, "1  1");
    
    /* Derivative ************************************************************/
    
    test_derivative("0", "0");
    test_derivative("1  2", "0");
    test_derivative("1  -1/1  2", "0");
    test_derivative("2  0 1", "1  1");
    test_derivative("3  1 0 1", "2  0 2");
    test_derivative("1  1/2  0 1", "1  -1/3  0 0 1");
    test_derivative("2  2 1/2  -1 1", "1  -3/3  1 -2 1");
    
    test_derivative("2  0 1/3  1 2 1", "2  1 -1/4  1 3 3 1");

    /* Bug which allowed constant factors */
    test_derivative("3  5 1 -2/2  10 2", "3  0 -10 -1/3  25 10 1");
    
    /* Evaluation ************************************************************/
    
    test_evaluate("1  1/1  2", -2, 3, "1/2");
    test_evaluate("3  1 0 1/2  0 1", -1, 2, "-5/2");
    test_evaluate("2  3 1/2  -1 1", 1, 1, "P");
    test_evaluate("2  3 1/2  -1 1", 2, 3, "-11");
    test_evaluate("2  3 1/2  -1 2", 1, 2, "P");
    test_evaluate("2  1 1/2  -1 1", 2, 1, "3");
    
    /* String methods ********************************************************/
    
    fmpz_poly_q_init(qpoly1);
    ans = fmpz_poly_q_set_str(qpoly1, "1  3/xyz");
    if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1))
    {
        flint_printf("test_set_str: failed\n");
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    
    fmpz_poly_q_init(qpoly1);
    ans = fmpz_poly_q_set_str(qpoly1, "abc/1  3");
    if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1))
    {
        flint_printf("test_set_str: failed\n");
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    
    fmpz_poly_q_init(qpoly1);
    ans = fmpz_poly_q_set_str(qpoly1, "abc/xyz");
    if ((ans == 0) || !fmpz_poly_q_is_zero(qpoly1))
    {
        flint_printf("test_set_str: failed\n");
        abort();
    }
    fmpz_poly_q_clear(qpoly1);
    
    test_get_str_pretty("1  -3", "-3");
    test_get_str_pretty("3  1 2 1", "t^2+2*t+1");
    test_get_str_pretty("1  -2/2  1 1", "-2/(t+1)");
    test_get_str_pretty("2  1 1/2  -1 1", "(t+1)/(t-1)");
    test_get_str_pretty("2  1 1/1  2", "(t+1)/2");
    test_get_str_pretty("1  1/1  2", "1/2");

    FLINT_TEST_CLEANUP(state);
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemple #19
0
int t_map()
{
	c_map map;

	c_map_create(&map, int_comparer);

	
	assert(__c_rb_tree_verify(map._l));
	printf("0. test create with insert unique\n");
	create_with_insert_unique(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n1. test clear\n");
	test_clear(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n2. test size and empty\n");
	test_size_empty(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n3. test create with insert equal\n");
	c_map_clear(&map);
	create_with_insert_equal(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n4. test swap\n");
	create_with_insert_unique(&map);
	test_swap(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n5. test create with insert unique1\n");
	create_with_insert_unique1(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n6. test create with insert equal1\n");
	c_map_clear(&map);
	create_with_insert_equal1(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n7. test create with insert unique2\n");
	c_map_clear(&map);
	create_with_insert_unique2(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n8. test create with insert equal2\n");
	c_map_clear(&map);
	create_with_insert_equal2(&map);
	print_map(&map);
	rprint_map(&map);
	assert(__c_rb_tree_verify(map._l));
	
	printf("\n\n9. test erase\n");
	c_map_clear(&map);
	create_with_insert_unique(&map);
	test_erase(&map);
	create_with_insert_unique(&map);	
	test_reverse_erase(&map);	
	print_map(&map);
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n10. test find and erase\n");
	c_map_clear(&map);
	printf("* test_find_erase:\n");
	create_with_insert_unique(&map);
	print_map(&map);	
	test_find_erase(&map);
	print_map(&map);	
	printf("* test_reverse_find_erase:\n");
	create_with_insert_unique(&map);
	print_map(&map);	
	test_reverse_find_erase(&map);
	print_map(&map);	
	assert(__c_rb_tree_verify(map._l));

	printf("\n\n11. test count:\n"); // 'lower_bound' 'upper_bound' 'equal_range' used	
	create_with_insert_unique(&map);
	test_count(&map);

	printf("\n\n12. test less:\n");
	test_less();

	printf("\n\n13. test equal:\n");
	test_equal();

	printf("\n\n14. test at:\n");
	test_at();
	
	c_map_destroy(&map);
	printf("\n\nfinish testing map!\n");
	return 0;
}