示例#1
0
def test_get_agent():
    name = 'test_get_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a1 = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a1.save()
    a2 = fuzzyio.Agent(id=a1.id)
    a2.get()
    assert a2.inputs['input1']['low'][0] == a1.inputs['input1']['low'][0]
示例#2
0
def test_update_agent():
    name = 'test_update_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a1 = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a1.save()
    a1.inputs['input2'] = {'low': [0, 1], 'medium': [0, 1, 2], 'high': [1, 2]}
    a1.save()

    a2 = fuzzyio.Agent(id=a1.id)
    a2.get()

    assert 'input2' in a2.inputs
示例#3
0
def test_save_new_agent():
    name = 'test_save_new_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    assert type(a.id) is UnicodeType
示例#4
0
def test_agent_keyword_constructor():
    name = 'test_agent_keyword_constructor'
    (inputs, outputs, rules) = default_agent()
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    assert a.inputs == inputs
    assert a.outputs == outputs
    assert a.rules == rules
示例#5
0
def test_delete_agent():
    name = 'test_delete_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a1 = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a1.save()
    a1.delete()
    # We shouldn't be able to get a deleted agent
    try:
        a2 = fuzzyio.Agent(id=a1.id)
        a2.get()
        assert False
    except fuzzyio.DeletedAgentError:
        assert True
    except:
        assert False
示例#6
0
def test_evaluation():
    name = 'test_evaluation'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = fuzzyio.evaluate_with_id(a.id, {'input1': 0.5})
    e = fuzzyio.Evaluation(evid)
    assert e.id == evid
    a.delete()
示例#7
0
def test_feedback():
    name = 'test_feedback'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = a.evaluate_with_id({'input1': 0.5})
    fb = fuzzyio.Feedback(evid, performance=8.1)
    assert fb.evid == evid
    assert fb.properties['performance'] == 8.1
    a.delete()
示例#8
0
def test_server_feedback():
    name = 'test_server_evaluate_with_id'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = fuzzyio.evaluate_with_id(a.id, {'input1': 0.5})
    fb = fuzzyio.feedback(evid, performance=8.1)
    assert type(fb.id) == UnicodeType
    assert type(fb.createdAt) == UnicodeType
    a.delete()
示例#9
0
def test_server_evaluate():
    name = 'test_evaluate_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    results = fuzzyio.evaluate(a.id, {'input1': 0.5})
    assert type(results) is DictionaryType
    assert 'output1' in results
    assert type(results['output1']) is FloatType
    a.delete()
示例#10
0
def test_get_nonexistent_agent():
    name = 'test_get_nonexistent_agent'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a1 = fuzzyio.Agent(id='***NONEXISTENT***')
    try:
        a1.get()
        assert False
    except fuzzyio.NoSuchAgentError:
        assert True
    except:
        assert False
示例#11
0
def test_agent_evaluate_with_id():
    name = 'test_agent_evaluate_with_id'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = a.evaluate_with_id({'input1': 1.5})
    assert type(evid) is StringType
    assert type(results) is DictionaryType
    assert 'output1' in results
    assert type(results['output1']) is FloatType
    a.delete()
示例#12
0
def test_get_feedback():
    name = 'test_get_feedback'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = a.evaluate_with_id({'input1': 0.5})
    fb = fuzzyio.Feedback(evid, performance=8.1)
    fb.save()
    e = fuzzyio.Evaluation(evid)
    fbs = e.feedback()
    assert type(fbs) == ListType
    assert len(fbs) == 1
    assert fbs[0]['id'] == fb.id
    a.delete()
示例#13
0
def test_get_evaluation():
    name = 'test_get_evaluation'
    (inputs, outputs, rules) = default_agent()
    fuzzyio.setup(API_KEY)
    a = fuzzyio.Agent(name=name, inputs=inputs, outputs=outputs, rules=rules)
    a.save()
    (results, evid) = fuzzyio.evaluate_with_id(a.id, {'input1': 0.5})
    e = fuzzyio.Evaluation(evid)
    e.get()
    assert type(e.id) == StringType
    assert type(e.input) == DictionaryType
    assert type(e.fuzzified) == DictionaryType
    assert type(e.rules) == ListType
    assert type(e.inferred) == DictionaryType
    assert type(e.clipped) == DictionaryType
    assert type(e.combined) == DictionaryType
    assert type(e.centroid) == DictionaryType
    assert type(e.crisp) == DictionaryType
    assert type(e.createdAt) == UnicodeType
    a.delete()
示例#14
0
def test_save_method():
    a = fuzzyio.Agent(AGENT_ID)
    assert type(a.save) is MethodType
示例#15
0
def test_agent_constructor():
    a = fuzzyio.Agent(AGENT_ID)
    assert type(a) is InstanceType
    assert type(a.id) is StringType
    assert a.id == AGENT_ID