コード例 #1
0
def manually_check(inputs):
    state = 'start'
    print state,
    for input_ in inputs:
        print input_
        state = delta(state, input_)
        print state, 
コード例 #2
0
def makeDFA():
    """Return the DFA."""
    dfa = Automata.DFA()
    dfa.alphabet = {bin(i)[2:].zfill(5) for i in range(32)}
    dfa.initial = 'start'
    dfa.transition = lambda st, a: delta(st, a)
    dfa.isfinal = lambda st: st in SINGLE_ENDED + ['done', 'start']
    return dfa
コード例 #3
0
def example_pass(example_type, example_id):
	if example_type in example_types:
		infile = get_infile(example_type, example_id)
		state_info = []
		state = 'start'
		for i in infile:
			current_state_info = { 'start': state, 'symbol': i }
			state = delta(state, i)
			current_state_info['end'] = state
			state_info.append(current_state_info)
		return render_template('example.html', viewModel={ 'states': infile, 'state_info': state_info })
コード例 #4
0
    def test_delta(self):

        result = {
            'set': {'a': {'b': 1}},
            'delete':{}
            }

        self.assertEqual(result, delta({}, {'a': {'b': 1}}))
        self.assertEqual(result, delta({'a': {'b': 2}}, {'a': {'b': 1}}))
        self.assertNotEqual(result, delta({'a': {'b': 1}}, {'a': {'b': 1}}))

        result = {
            'set': {},
            'delete':{'a': {'b': 1}}
            }

        self.assertEqual(result, delta({'a': {'b': 1}}, {}))
        self.assertNotEqual(result, delta({'a': {'b': 1}}, {'a': {'b': 1}}))

        self.assertEqual(self.dict1, delta({}, self.dict1)['set'])
        self.assertEqual(self.dict1, delta(self.dict1, {})['delete'])
コード例 #5
0
ファイル: example.py プロジェクト: ITUPythonStudyGroup/differ
from delta import *
import json

person = {
    'name': 'Andreas',
    'skills': {
        'matlab': 3,
        'swift': 2
    },
    'age': 25
}

personLater = {
    'name': 'Andreas',
    'skills': {
        'python': 3,
        'swift': 3
    },
    'age': 26
}

print("Delta format:")
print(json.dumps(delta(person, personLater), indent = 4))
print("result of delta plus merge:")
print(json.dumps(merge(person, delta(person, personLater)), indent = 4))
コード例 #6
0
 def test_package(self):
     self.assertEqual(self.dict2, merge(self.dict1, delta(self.dict1, self.dict2)))
     self.assertEqual(self.dict1, merge(self.dict2, delta(self.dict2, self.dict1)))