예제 #1
0
def test_run_gets():
    # on a non-default port
    # start the script
    cwd = os.getcwd()
    server_script = os.path.join(cwd, "tests", "server_script_61982.py")
    server_pipe = Popen(['python', server_script], cwd=cwd)

    sock = Socket('client', port=61982)

    pars = (np.array([0, 1, 2, 3]), np.array([1, 3, 2, 4]))
    settings = (np.array([0, 1, 2]), )
    cons = ()

    reply = sock.tcpcmd({'command': 'getset'})
    assert_array_equal(settings,
                       reply,
                       err_msg='settings not echoed correctly')

    reply = sock.tcpcmd({'command': 'getpar'})
    assert_array_equal(pars, reply, err_msg='settings not echoed correctly')

    reply = sock.tcpcmd({'command': 'getcon'})
    assert_array_equal(cons, reply, err_msg='cons not echoed correctly')

    sock.tcpcmd({'command': 'done'})
예제 #2
0
def test_run_obes():
    # on a non-default port
    # start the script
    cwd = os.getcwd()
    server_script = os.path.join(cwd, "tests", "server_script_61983.py")
    server_pipe = Popen(['python', server_script], cwd=cwd)

    sock = Socket('client', port=61983)

    # test initial weights
    weights = np.ones(4) / 4.0
    reply = sock.tcpcmd({'command': 'getwgt'})
    assert_array_equal(weights, reply, err_msg='weights not echoed correctly')

    # test pdf_update()
    measurement = ((1, ), 5.0, 1.0)
    sets, ymeas, sig = measurement

    ymodel = np.array((1, 4, 4, 7))
    lkl = np.exp(-(ymodel - ymeas)**2 / 2)
    weights = lkl / np.sum(lkl)
    reply = sock.tcpcmd({'command': 'newdat', 'x': sets, 'y': ymeas, 's': sig})
    assert reply == "OK"

    reply = sock.tcpcmd({'command': 'getwgt'})
    assert_array_equal(weights, reply, err_msg="incorrect updated weights")

    sock.tcpcmd({'command': 'done'})
예제 #3
0
def test_run_pdf():
    # on a non-default port
    # start the script
    cwd = os.getcwd()
    server_script = os.path.join(cwd, "tests", "server_script_61984.py")
    server_pipe = Popen(['python', server_script], cwd=cwd)

    sock = Socket('client', port=61984)

    right_mean = [1.5, 2.5]
    reply = sock.tcpcmd({'command': 'getmean'})
    assert_array_equal(right_mean, reply,
                       err_msg='incorrect mean returned')

    right_std = np.sqrt(np.array([1, 1]) * 5.0 / 4.0)
    reply = sock.tcpcmd({'command': 'getstd'})
    assert_array_almost_equal(right_std, reply,
                       err_msg='incorrect std deviation returned')

    right_cov = np.array([[5.0 / 3.0, 4.0 / 3.0], [4.0 / 3.0, 5.0 / 3.0]])
    reply = sock.tcpcmd({'command': 'getcov'})
    assert_array_almost_equal(right_cov, reply,
                       err_msg='incorrect covariance returned')

    sock.tcpcmd({'command': 'done'})
예제 #4
0
import numpy as np
from numpy.testing import assert_array_equal

from optbayesexpt import Socket

myClient = Socket('client', port=60899)
myServer = Socket('server', port=60899)


def test_send_recieve_text():
    contents = 'test message'
    myClient.send(contents)
    received = myServer.receive()
    myClient.close()
    assert received == contents


def test_send_recieve_number():
    contents = 3.1415
    myClient.send(contents)
    received = myServer.receive()
    myClient.close()
    assert received == contents


def test_send_recieve_array():
    contents = [1, 2, 3]
    myClient.send(contents)
    received = myServer.receive()
    myClient.close()
    assert received == contents