Skip to content

Commit

Permalink
- Is sequence of int support.
Browse files Browse the repository at this point in the history
-  Addresses #108.
  • Loading branch information
bandurvp committed Sep 1, 2017
1 parent c426bc3 commit f534a26
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
12 changes: 12 additions & 0 deletions c/vdmclib/src/main/VdmBasicTypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ TVP isIntGC(TVP v, TVP *from)
return newBoolGC(false, from);
}

TVP isSeqOfInt(TVP v)
{
if(v->type == VDM_SEQ)
{
if((((struct Collection *)(v->value.ptr)))->size == 0)
return newBool(true);
if((((struct Collection *)(v->value.ptr)))->value[0]->type == VDM_INT)
return newBool(true);
return newBool(false);
}
}

TVP isNat(TVP v)
{
if(v->type == VDM_INT)
Expand Down
1 change: 1 addition & 0 deletions c/vdmclib/src/main/VdmBasicTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ TVP isChar(TVP val);
TVP isCharGC(TVP val, TVP *from);
TVP isToken(TVP val);
TVP isTokenGC(TVP val, TVP *from);
TVP isSeqOfInt(TVP v);
int toInteger(TVP a);
double toDouble(TVP a);
bool toBool(TVP a);
Expand Down
19 changes: 17 additions & 2 deletions c/vdmclib/src/test/Expressions_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TVP letFilter1Exp()
{
TVP res =NULL;
{ //let b = 2 in
// b
// b
TVP tmp1 = newInt(2);
{
//let 1 = b in
Expand Down Expand Up @@ -275,7 +275,7 @@ TEST(Expression, letFilter1Exp)
}

if(!failed)
FAIL();
FAIL();
vdmFree (TEST_TRUE);
}

Expand Down Expand Up @@ -374,3 +374,18 @@ TEST(Expression, isToken)

vdmFree(res);
}

TEST(Expression, isSeqOfInt)
{
TVP res = isSeqOfInt(newSeqVar(1, newInt(1)));

EXPECT_TRUE(res->value.boolVal);

vdmFree(res);

res = isSeqOfInt(newSeqVar(1, newReal(1)));

EXPECT_FALSE(res->value.boolVal);

vdmFree(res);
}

0 comments on commit f534a26

Please sign in to comment.