Esempio n. 1
0
/**
 * test_FSM_state:
 * @fn test_FSM_state
 * Tests `compilerkit_FSM_*_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_states (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("zero");
    compilerkit_FSM_add_state (fsm, "one");
    compilerkit_FSM_add_state (fsm, "two");
    compilerkit_FSM_add_state (fsm, "three");
    
    g_assert (compilerkit_FSM_has_state (fsm, "zero"));
    g_assert (compilerkit_FSM_has_state (fsm, "one"));
    g_assert (compilerkit_FSM_has_state (fsm, "two"));
    g_assert (compilerkit_FSM_has_state (fsm, "three"));
    g_assert (!compilerkit_FSM_has_state (fsm, "four"));
    g_assert (!compilerkit_FSM_has_state (fsm, NULL));
    
    compilerkit_FSM_add_transition (fsm, "zero", "five", '5');
    compilerkit_FSM_add_accepting_state (fsm, "six");
    g_assert (compilerkit_FSM_has_state (fsm, "five"));
    g_assert (compilerkit_FSM_has_state (fsm, "six"));
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
Esempio n. 2
0
/**
 * test_FSM_start_state:
 * @fn test_FSM_set_start_state
 * Tests `compilerkit_FSM_*_start_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_start_state (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM start_state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("constructor");
    g_assert (g_strcmp0 (compilerkit_FSM_get_start_state (fsm), "constructor") == 0);
    compilerkit_FSM_set_start_state (fsm, "start_state");

    g_assert (g_strcmp0 (compilerkit_FSM_get_start_state (fsm), "start_state") == 0);

    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
Esempio n. 3
0
/**
 * test_FSM_state:
 * @fn test_FSM_state
 * Tests `compilerkit_FSM_*_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_states (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("zero");
    compilerkit_FSM_add_transition(fsm,"zero","one","a");
    compilerkit_FSM_add_transition(fsm,"zero","two","b");

    g_assert(compilerkit_FSM_has_state(fsm,"zero"));
    g_assert(compilerkit_FSM_has_state(fsm,"one"));

    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
Esempio n. 4
0
// Build up the state machine. Should match "fsm" or "demo", separated by (but not ending with) spaces.
CompilerKitFSM *state_machine ()
{
    CompilerKitFSM* fsm; // Creates pointer for FSM

    fsm = compilerkit_FSM_new("A");  // Calls the constructor for the FSM
    printf("Object created\r\n");
//    compilerkit_FSM_set_start_state(fsm, "A");
    compilerkit_FSM_add_transition (fsm, "A", "B", 'd');
    compilerkit_FSM_add_transition (fsm, "A", "F", 'f');
    compilerkit_FSM_add_transition (fsm, "B", "C", 'e');
    compilerkit_FSM_add_transition (fsm, "C", "D", 'm');
    compilerkit_FSM_add_transition (fsm, "D", "E", 'o');
    compilerkit_FSM_add_transition (fsm, "E", "A", ' ');
    compilerkit_FSM_add_transition (fsm, "F", "G", 's');
    compilerkit_FSM_add_transition (fsm, "G", "H", 'm');
    compilerkit_FSM_add_transition (fsm, "H", "A", ' ');
    printf("Transitions added\r\n");
    compilerkit_FSM_add_end_state (fsm, "F");
    compilerkit_FSM_add_end_state (fsm, "E");
    compilerkit_FSM_add_end_state (fsm, "H");
    printf("End states added\r\n");
    return fsm;
}