示例#1
0
/**
 * compilerkit_concatenation_new:
 * @fn compilerkit_concatenation_new
 * @memberof CompilerKitConcatenation
 * Construct a CompilerKitConcatenation instance.
 * @pre GObject* are all non NULL.
 * @param GObject* Left side of concatenation
 * @param GObject* Right side of concatenation
 * @return A new CompilerKitConcatenation struct if concatenation is necessary otherwise return the single element or EmptySet.
 */
GObject *compilerkit_concatenation_new (GObject *left, GObject *right)
{
	CompilerKitConcatenation* result;

	if (COMPILERKIT_IS_EMPTY_SET(left) || COMPILERKIT_IS_EMPTY_SET(right)) // If left or right is EmptySet
		return compilerkit_empty_set_get_instance();
	if (COMPILERKIT_IS_EMPTY_STRING(left)) // If left is EmptyString, return right
		return right;
	if (COMPILERKIT_IS_EMPTY_STRING(right)) // If right is EmpltyString, return left
		return left;

    result = COMPILERKIT_CONCATENATION (g_object_new (COMPILERKIT_TYPE_CONCATENATION, NULL));
    result->priv->left = left;
    result->priv->right = right;
    return G_OBJECT(result);
}
/**
 * test_concatenation_constructor_empty_set:
 * @fn test_concatenation_constructor_empty_set
 * Tests compilerkit_concatenation_new in CompilerKitConcatenation struct when either side is an empty set.
 * @pre None
 * @param None
 * @return void
 */
void test_concatenation_constructor_empty_set (void)
{
	GObject* ckc;
	GObject* left;
	GObject* right;

    g_test_message ("Testing concatenation constructor when either side is an empty set");
    g_test_timer_start ();

	// Right parameter is EmptySet
    {
        left = compilerkit_symbol_new('a');
        right = compilerkit_empty_set_get_instance ();
        ckc = compilerkit_concatenation_new(left,right);

        // Assert that ckc is the empty set, and that emptyset is a singleton.
        g_assert (right == ckc);
        g_assert(COMPILERKIT_IS_EMPTY_SET(ckc));

        g_object_unref (left);
        g_object_unref (right);
    }

	// Left parameter is EmptySet
    {
        left = compilerkit_empty_set_get_instance();
        right = compilerkit_symbol_new('a');
        ckc = compilerkit_concatenation_new(left,right);

        // Assert that concatenation is returning the empty set here.
        g_assert (ckc == left);
        g_assert (COMPILERKIT_IS_EMPTY_SET(ckc));

        g_object_unref (left);
        g_object_unref (right);
    }

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
示例#3
0
/**
 * test_kleene_star_constructor:
 * @fn test_kleene_star_constructor
 * Tests compilerkit_kleene_star_new in CompilerKitKleeneStar struct.
 * @pre None
 * @param None
 * @return void
 */
void test_kleene_star_constructor (void)
{
	GObject* e_set;
	GObject* e_string;
	GObject* a;
	GObject* result;
	
	
    g_test_message ("Testing KleeneStar method");
    g_test_timer_start ();
	
	
	//empty set
	{
	
		e_set = compilerkit_empty_set_get_instance();
		result = compilerkit_kleene_star_new(e_set);
		g_assert(COMPILERKIT_IS_EMPTY_SET (result));
        g_object_unref (result);
	}
	
	//empty string
	{
		e_string = compilerkit_empty_string_get_instance();
		result = compilerkit_kleene_star_new(e_string);
		g_assert(COMPILERKIT_IS_EMPTY_STRING (result));
        g_object_unref (result);
	}
	
	//symbol
	{
		a = compilerkit_symbol_new('a');
		result = compilerkit_kleene_star_new(a);
		g_assert(COMPILERKIT_IS_KLEENE_STAR (result));
        g_object_unref (result);
	}
    
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
示例#4
0
/* ToNfa empty set. */
static GObject *to_nfa_empty_set (CompilerKitVisitor *self, GObject *obj)
{
    g_assert(COMPILERKIT_IS_EMPTY_SET(obj));

    return NULL;
}