TEST(ExpressionProduct, productExp)
{
	TVP TEST_TRUE = newBool(true);

	TVP result = productExp();

	EXPECT_EQ (true,equals(TEST_TRUE,result));

	recursiveFree(result);

	recursiveFree (TEST_TRUE);
}
Exemplo n.º 2
0
TEST(Expression_Map, mapApply)
{
	TVP TEST_TRUE = newBool(true);

	TVP result = mapApply();

	EXPECT_EQ (true,equals(TEST_TRUE,result));

	recursiveFree(result);

	recursiveFree (TEST_TRUE);
}
TEST(Statements, recordR1)
{
	TVP TEST_TRUE = newBool(true);

	TVP result = recordR1();

	EXPECT_EQ (true,equals(TEST_TRUE,result));

	recursiveFree(result);

	recursiveFree (TEST_TRUE);
}
Exemplo n.º 4
0
TEST(Expression_Seq, seqLen)
{
	int arr[] =
	{ 1, 2 };
	TVP t = newSequence(2,arr);

	TVP res = vdmSeqLen(t);

	EXPECT_EQ(2, res->value.intVal);
	recursiveFree(res);
//
	recursiveFree(t);
}
Exemplo n.º 5
0
TEST(Expression_Map, mapDom)
{
	//map1: {1|->2,3|->4,6|->7}
	TVP map = createMap1();

	//Get domain (returns a set)
	TVP map_dom = vdmMapDom(map);

	TVP res = vdmSetMemberOf(map_dom,newInt(3));
	EXPECT_EQ(true, res->value.boolVal);

	recursiveFree(map_dom);
	recursiveFree(res);
}
Exemplo n.º 6
0
TEST(Expression_Seq, seqTl)
{
	int arr[] =
	{ 1, 2 };
	TVP t = newSequence(2,arr);

	TVP res = vdmSeqTl(t);

	struct Collection* col = (struct Collection*) res->value.ptr;

	EXPECT_EQ(2, col->value[0]->value.intVal);
	recursiveFree(res);
//
	recursiveFree(t);
}
Exemplo n.º 7
0
TEST(Expression_Seq, seqIndex)
{
	int arr[] =
	{ 1, 2 };
	TVP t = newSequence(2,arr);

	TVP index = newInt(2);
	TVP res = vdmSeqIndex(t,index);

	EXPECT_EQ(2, res->value.intVal);
	recursiveFree(res);
//
	recursiveFree(t);
	recursiveFree(index);
}
Exemplo n.º 8
0
void init(){
    // Read the first line containing number of patients
    int tmp ;
    scanf("%d",&tmp);

    // Read into binary tree
    struct node * tree ;
    int i = 0 ;
    for ( i = 0 ; i < tmp ; i++){
        if ( i == 0 ) tree = makeNode(readPatient());
        else{
            insert(&tree,readPatient());
        }
    }

    // Read line containing number of queries.
    scanf("%d",&tmp);
    // Loop tmp number of times, reading the two queries, finding the query, and printing the value
    for ( i = 0 ; i < tmp ; i++ ){
        char * organQ = (char *)malloc(sizeof(char)*20);
        char * bloodtypeQ = (char *)malloc(sizeof(char)*20);
        organT * rtn = NULL ;
        scanf("%s %s",organQ,bloodtypeQ);

        getQuery(&rtn, tree,organQ,bloodtypeQ);
        printPatient((rtn));

        free(organQ);
        free(bloodtypeQ);
        free(rtn);
    }
    recursiveFree(tree);
}
Exemplo n.º 9
0
TEST(Expression_Seq, seqInEqual)
{
	int arr[] =
	{ 1 };
	TVP t = newSequence(1,arr);

	int arr2[] =
	{ 2 };
	TVP t2 = newSequence(1,arr2);

	TVP res = vdmSeqInEqual(t,t2);

	EXPECT_EQ(true, res->value.boolVal);
	recursiveFree(res);
	//
	recursiveFree(t);
	recursiveFree(t2);
}
Exemplo n.º 10
0
TEST(Expression_Seq, seqInds)
{
	int arr[] =
	{ 1, 2 };
	TVP t = newSequence(2,arr);

	TVP res = vdmSeqInds(t);

	EXPECT_EQ(VDM_SET, res->type);
	struct Collection* col = (struct Collection*) res->value.ptr;

	EXPECT_TRUE(VDM_SET == res->type);
	//TODO this is actually not the VDM version of inds [1,2] = {1,2}, the second set and the set,set comp is missing, I didnt do sets yet
	EXPECT_TRUE(2 == col->value[0]->value.intVal || 2 == col->value[1]->value.intVal);
	EXPECT_TRUE(1 == col->value[0]->value.intVal || 1 == col->value[1]->value.intVal);

	recursiveFree(res);
//
	recursiveFree(t);
}
Exemplo n.º 11
0
TEST(Expression_Seq, seqConc)
{
	int arr[] =
	{ 1 };
	TVP t = newSequence(1,arr);

	int arr2[] =
	{ 2 };
	TVP t2 = newSequence(1,arr2);

	TVP res = vdmSeqConc(t,t2);

	struct Collection* col = (struct Collection*) res->value.ptr;

	EXPECT_EQ(1, col->value[0]->value.intVal);
	EXPECT_EQ(2, col->value[1]->value.intVal);

	recursiveFree(res);
//
	recursiveFree(t);
	recursiveFree(t2);
}
Exemplo n.º 12
0
TEST(Expression_Seq, seqElems)
{
	int arr[] =
	{ 1, 2 };
	TVP t = newSequence(2,arr);

	TVP a = newInt(1);
	TVP b = newInt(2);
	TVP elems = newSetVar(2, a,b);

	TVP res = vdmSeqElems(t);

	TVP tmp = vdmEquals(res,elems);
	EXPECT_EQ(true, tmp->value.boolVal);
	recursiveFree(res);
	vdmFree(a);
	vdmFree(b);
	vdmFree(tmp);
	vdmFree(elems);
//
	recursiveFree(t);
}
Exemplo n.º 13
0
void ObjectMemory::EmptyZct()
{
	if (m_bIsReconcilingZct)
		__debugbreak();
#ifdef _DEBUG
	nDeleted = 0;

	if (!alwaysReconcileOnAdd || Interpreter::executionTrace)
		CHECKREFSNOFIX
	else
		checkStackRefs();
#endif

	// Bump the refs from the stack. Any objects remaining in the ZCT with zero counts
	// are truly garbage.
	Interpreter::IncStackRefs();

	OTE** pZct = m_pZct;
	// This tells us that we are in the process of reconcilation
	m_bIsReconcilingZct = true;
	const int nOldZctEntries = m_nZctEntries;
	m_nZctEntries = -1;

	for (int i=0;i<nOldZctEntries;i++)
	{
		OTE* ote = pZct[i];
		if (!ote->isFree() && ote->m_flags.m_count == 0)
		{
			// Note that deallocate cannot make new Zct entries
			// Because we have bumped the ref. counts of all stack ref'd objects, only true
			// garbage objects can ever have a ref. count of zero. Therefore if recursively
			// counting down throws up new zero ref. counts, these should not be added to 
			// the Zct, but deallocated. To achieve this we set a global flag to indicate
			// that we are reconciling, see AddToZct() above. 
#ifdef _DEBUG
			nDeleted++;
#endif
			recursiveFree(ote);
		}
	}

//	CHECKREFSNOFIX
}
Exemplo n.º 14
0
TVP productExp()
{
	TVP tmp1 = newProduct(2);

	TVP tmp1_1 = newInt(1);
	productSet(tmp1,1,tmp1_1);
	recursiveFree(tmp1_1);

	TVP tmp1_2 = newInt(2);
	productSet(tmp1,2,tmp1_2);
	recursiveFree(tmp1_2);


	TVP tmp2_1 = newInt(1);
	TVP tmp2_2 = newInt(2);
	TVP args[2] = {tmp2_1,tmp2_2};
	TVP tmp2 = newProductWithValues(2,args);
	recursiveFree(tmp2_1);
	recursiveFree(tmp2_2);

//
//	TVP tmp2_1 = newInt(1);
//	productSet(tmp2,1,tmp2_1);
//	recursiveFree(tmp2_1);
//
//	TVP tmp2_2 = newInt(2);
//	productSet(tmp2,2,tmp2_2);
//	recursiveFree(tmp2_2);

	TVP res =newBool(equals(tmp1,tmp2));

	//scope cleanup
	recursiveFree(tmp1);
	recursiveFree(tmp2);

	return res;
}
Exemplo n.º 15
0
// Count down and deallocate an Object - only performed when reconciling
// the Zct.
//
void ObjectMemory::recursiveCountDown(OTE* ote)
{
	if (ote->decRefs())
		recursiveFree(ote);
}
Exemplo n.º 16
0
void Trie::recursiveFree(Node* node){
    for(int i=0; i<branches; i++)
        if(node->children[i]!=NULL)
            recursiveFree(node->children[i]);
    delete node;
}
Exemplo n.º 17
0
// Memory
Trie::~Trie(){
    recursiveFree(root);
}