예제 #1
0
파일: main.cpp 프로젝트: gatesyp/coursework
int main()
{
    test_find();
    test_equals();
    test_min();
    test_min_element(); 
    test_copies();
    std::cout << "Success!" << std::endl;
    return 0;
}
void test(){
	test_sum();
	test_max();
	test_min();
	test_second_max();
	test_second_min();
	test_equal();
	test_occurences();
	test_countNegatives();
	test_indexOf();
	test_clearWith();
	test_insertElement();
	test_removeElement();
	test_copy();
	test_merge();
	test_reverse();
	test_sort();
	printf("All passed!!!!");
}
예제 #3
0
void elim ( short trans )
    {
    struct matrix * rp;
    ROWP pp, ppp;
    short val1, val2, div, gcd1;
#define myABS(A) ( ( (short)(A) >= (short)0 ) ? (A) : -(A) )

    pp = oldmp->rowp;
    for ( ppp = pp+(2*(*pp)+1) ; (short)(*(ppp++)) != (short)trans ; ppp++ );
    val1 = *ppp;
    for ( rp = oldmm; rp != NULL; rp = rp->next ) {
	pp = rp->rowp;
	for ( ppp = pp+(2*(*pp)+1) ;
	      (short)(*(ppp++)) != (short)trans ; ppp++ );
	val2 = - *ppp;
	div = gcd( val1, val2 );
	{ int j, j1, j2; short val; register ROWP point, point1, point2;
	  for ( j = 0, gcd1 = 0, point = newrow + 1,
		j1 = *(point1 = oldmp->rowp), point1++,
		j2 = *(point2 = rp->rowp), point2++;
		j1 > 0 && j2 > 0 ; ) {
	      if ( *point1 == *point2 ) {
		  j1--; j2--;
		  *(point++) = *(point1++); point2++;
		  if ( (short)( val =
			  (val2 * *(point1++) + val1 * *(point2++)) / div
			     ) == (short)0 )
		    *(--point) = 0;
		  else{
		      *(point++) = val; j++;
		      if ( gcd1 != (short)1 ) {
			  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
			  else  gcd1 = gcd( myABS(val), gcd1 );
			}
		    }
		}
	      else if ( *point1 > *point2 ) {
		  j++; j2--;
		  *(point++) = *(point2++);
		  val = *(point++) = (short)( (val1 * *(point2++)) / div );
		  if ( gcd1 != (short)1 ) {
		      if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		      else  gcd1 = gcd( myABS(val), gcd1 );
		    }
		}
	      else {
		  j++; j1--;
		  *(point++) = *(point1++);
		  val = *(point++) = (short)( (val2 * *(point1++)) / div );
		  if ( gcd1 != (short)1 ) {
		      if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		      else  gcd1 = gcd( myABS(val), gcd1 );
		    }
		}
	    }
	  while ( j1-- > 0 ) {
	      j++;
	      *(point++) = *(point1++);
	      val = *(point++) = (short)( (val2 * *(point1++)) / div );
	      if ( gcd1 != (short)1 ) {
		  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		  else  gcd1 = gcd( myABS(val), gcd1 );
		}
	    }
	  while ( j2-- > 0 ) {
	      j++;
	      *(point++) = *(point2++);
	      val = *(point++) = (short)( (val1 * *(point2++)) / div );
	      if ( gcd1 != (short)1 ) {
		  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		  else  gcd1 = gcd( myABS(val), gcd1 );
		}
	    }
	  *newrow = j;
	  while ( ( (short)(*point1) != (short)0 ) &&
		  ( (short)(*point2) != (short)0 ) )  {
	      if ( *point1 == *point2 ) {
		  *(point++) = *(point1++); point2++;
		  if ( (short)( val =
			  (val2 * *(point1++) + val1 * *(point2++)) / div
			     ) == (short)0 )
		    *(--point) = 0;
		  else {
		      *(point++) = val; j++;
		      if ( gcd1 != (short)1 ) {
			  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
			  else  gcd1 = gcd( myABS(val), gcd1 );
			}
		    }
		}
	      else if ( *point1 > *point2 ) {
		  *(point++) = *(point2++); j++;
		  val = *(point++) = (short)( (val1 * *(point2++)) / div );
		  if ( gcd1 != (short)1 ) {
		      if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		      else  gcd1 = gcd( myABS(val), gcd1 );
		    }
		}
	      else {
		  *(point++) = *(point1++); j++;
		  val = *(point++) = (short)( (val2 * *(point1++)) / div );
		  if ( gcd1 != (short)1 ) {
		      if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		      else  gcd1 = gcd( myABS(val), gcd1 );
		    }
		}
	    }
	  while ( (short)(*point1) != (short)0 ) {
	      j++; *(point++) = *(point1++);
	      val = *(point++) = (short)( (val2 * *(point1++)) / div );
	      if ( gcd1 != (short)1 ) {
		  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		  else  gcd1 = gcd( myABS(val), gcd1 );
		}
	    }
	  while ( (short)(*point2) != (short)0 ) {
	      j++; *(point++) = *(point2++);
	      val = *(point++) = (short)( (val1 * *(point2++)) / div );
	      if ( gcd1 != (short)1 ) {
		  if ( gcd1 == (short)0 )  gcd1 = myABS(val);
		  else  gcd1 = gcd( myABS(val), gcd1 );
		}
	    }
	  *point = 0;
	  if ( test_min( newrow ) ) {
	      newm = (struct matrix *)emalloc(MAT_SIZE);
	      newm->next = mat; mat = newm;
	      newm->rowp = point = (ROWP)emalloc((unsigned)(2*(j+1)*ITM_SIZE));
	      for ( j = *(point1 = newrow), *(point++) = j, point1++;
		    j-- > 0 ;
		    *(point++) = *(point1++), *(point++) = *(point1++)/gcd1 );
	      while ( (short)(*point1) != (short)0 ) {
		  *(point++) = *(point1++);
		  if ( (*(point++) = *(point1++)/gcd1) > 0 )
		      ++(n_pos[(int)*(point-2)]);
		  else
		      ++(n_neg[(int)*(point-2)]);
		}
	      *(point) = 0;
#ifdef DEBUG
printf("new row ");
for ( j = *(point = newm->rowp), printf(" %d :\n",(int)j), point++; j-- > 0 ;
printf("  %d",(int)(*(point++)) ), printf(" %d,",(int)(*(point++)) ) );
while ( (short)(*point) != (short)0 ) {
printf(";  %d",(int)(*(point++)) );
printf(" %d",(int)(*(point++)) );
}
printf("\n");
#endif
	    }
	}
      }
}
예제 #4
0
int main()
{
    res.defi = -1;
    res.defd = -0.999;
    res.defl = -123;
    res.add_int = 0;
    res.add_real = 0.0;
    res.add_long = 0;

    int ints[MAX];
    double reals[MAX];
    long long longs[MAX];
    Value val_ints[MAX];
    Value val_reals[MAX];
    Value val_longs[MAX];

    Tuple *tuples[MAX];

    for (int i = 0; i < MAX; ++i) {
        ints[i] = i + 1;
        reals[i] = i + 0.5;
        longs[i] = 0x7000ffffffffffff;

        val_ints[i] = val_new_int(&ints[i]);
        val_reals[i] = val_new_real(&reals[i]);
        val_longs[i] = val_new_long(&longs[i]);

        if (i == 0 || ints[i] > res.max_int)
            res.max_int = ints[i];
        if (i == 0 || reals[i] > res.max_real)
            res.max_real = reals[i];
        if (i == 0 || longs[i] > res.max_long)
            res.max_long = longs[i];

        if (i == 0 || ints[i] < res.min_int)
            res.min_int = ints[i];
        if (i == 0 || reals[1] < res.min_real)
            res.min_real = reals[i];
        if (i == 0 || longs[i] < res.min_long)
            res.min_long = longs[i];

        res.add_int += ints[i];
        res.add_real += reals[i];
        res.add_long += longs[i];
    }

    res.avg_int = (double) res.add_int / MAX;
    res.avg_real = res.add_real / MAX;
    res.avg_long = (double) res.add_long / MAX;

    Value vals[3];
    for (int i = 0; i < MAX; ++i) {
        vals[0] = val_ints[i];
        vals[1] = val_reals[i];
        vals[2] = val_longs[i];

        tuples[i] = tuple_new(vals, 3);
    }

    test_cnt(tuples);
    test_min(tuples);
    test_max(tuples);
    test_avg(tuples);
    test_add(tuples);

    for (int i = 0; i < MAX; ++i)
        tuple_free(tuples[i]);

    return 0;
}