Esempio n. 1
0
def test_neg_assign():

    x = Bits(4, -1)
    assert x == 0b1111
    assert x.uint() == 0b1111
    x = Bits(4, -2)
    assert x == 0b1110
    assert x.uint() == 0b1110
Esempio n. 2
0
def test_neg_assign():

  x = Bits( 4, -1 )
  assert x        == 0b1111
  assert x.uint() == 0b1111
  x = Bits( 4, -2 )
  assert x        == 0b1110
  assert x.uint() == 0b1110
Esempio n. 3
0
def test_set_bit():

    x = Bits(4, 0b1100)
    x[3] = 0
    assert x.uint() == 0b0100
    x[2] = 1
    assert x.uint() == 0b0100
    x[1] = 1
    assert x.uint() == 0b0110
Esempio n. 4
0
def test_set_bit():

  x = Bits( 4, 0b1100 )
  x[3] = 0
  assert x.uint() == 0b0100
  x[2] = 1
  assert x.uint() == 0b0100
  x[1] = 1
  assert x.uint() == 0b0110
Esempio n. 5
0
def test_lt():

  x = Bits( 4, 0b1100 )
  y = Bits( 4, 0b0011 )
  assert y.uint() < x.uint()
  assert y.uint() < 10
  assert y < x.uint()
  assert y < 10
  assert y < x
  assert 1 < y
Esempio n. 6
0
def test_gt():

  x = Bits( 4, 0b1100 )
  y = Bits( 4, 0b0011 )
  assert x.uint() > y.uint()
  assert x.uint() > 2
  assert x > y.uint()
  assert x > 2
  assert x > y
  assert 9 > y
Esempio n. 7
0
def test_gt():

    x = Bits(4, 0b1100)
    y = Bits(4, 0b0011)
    assert x.uint() > y.uint()
    assert x.uint() > 2
    assert x > y.uint()
    assert x > 2
    assert x > y
    assert 9 > y
Esempio n. 8
0
def test_lt():

    x = Bits(4, 0b1100)
    y = Bits(4, 0b0011)
    assert y.uint() < x.uint()
    assert y.uint() < 10
    assert y < x.uint()
    assert y < 10
    assert y < x
    assert 1 < y
Esempio n. 9
0
def test_ne():

    x = Bits(4, 0b1100)
    y = Bits(4, 0b0011)
    # TODO: check width?
    assert x.uint() != y.uint()
    assert x != y
    # added for bug
    z = Bits(1, 0)
    assert z.uint() != 1L
    assert z != 1L
    assert 5 != x

    assert z != None
    assert Bits(4, 0) != None
Esempio n. 10
0
def test_ne():

  x = Bits( 4, 0b1100 )
  y = Bits( 4, 0b0011 )
  # TODO: check width?
  assert x.uint() != y.uint()
  assert x != y
  # added for bug
  z = Bits( 1, 0 )
  assert z.uint() != 1L
  assert z != 1L
  assert 5 != x

  assert z != None
  assert Bits( 4, 0 ) != None
Esempio n. 11
0
def test_return_type():

  x = Bits( 8, 0b1100 )
  assert isinstance( x.uint(), int  )
  assert isinstance( x.int(),  int  )
  assert isinstance( x[1:2],   Bits )
  assert isinstance( x[0:4],   Bits )
  assert isinstance( x[2],     Bits )
Esempio n. 12
0
def test_return_type():

    x = Bits(8, 0b1100)
    assert isinstance(x.uint(), int)
    assert isinstance(x.int(), int)
    assert isinstance(x[1:2], Bits)
    assert isinstance(x[0:4], Bits)
    assert isinstance(x[2], Bits)
Esempio n. 13
0
def test_set_slice():

  x = Bits( 4, 0b1100 )
  x[:] = 0b0010
  assert x.uint() == 0b0010
  x[2:4] = 0b11
  assert x.uint() == 0b1110
  x[0:1] = 0b1
  assert x.uint() == 0b1111
  x[1:3] = 0b10
  assert x.uint() == 0b1101
  # check open ended ranges
  x[1:] = 0b001
  assert x.uint() == 0b0011
  x[:3] = 0b110
  assert x.uint() == 0b0110

  with pytest.raises( ValueError ):
    x[1:3] = 0b110

  x[:]   = 0b1111
  assert x.uint() == 0b1111

  with pytest.raises( ValueError ):
    x[:]   = 0b10000
Esempio n. 14
0
def test_set_slice():

    x = Bits(4, 0b1100)
    x[:] = 0b0010
    assert x.uint() == 0b0010
    x[2:4] = 0b11
    assert x.uint() == 0b1110
    x[0:1] = 0b1
    assert x.uint() == 0b1111
    x[1:3] = 0b10
    assert x.uint() == 0b1101
    # check open ended ranges
    x[1:] = 0b001
    assert x.uint() == 0b0011
    x[:3] = 0b110
    assert x.uint() == 0b0110

    with pytest.raises(ValueError):
        x[1:3] = 0b110

    x[:] = 0b1111
    assert x.uint() == 0b1111

    with pytest.raises(ValueError):
        x[:] = 0b10000
Esempio n. 15
0
def test_lte():

  x = Bits( 4, 0b1100 )
  y = Bits( 4, 0b0011 )
  z = Bits( 4, 0b0011 )
  assert y.uint() <= x.uint()
  assert y.uint() <= 10
  assert y.uint() <= z.uint()
  assert y.uint() <= 0b0011
  assert y <= x.uint()
  assert y <= 10
  assert y <= z.uint()
  assert y <= 0b0011
  assert y <= x
  assert y <= z
  assert z <= x
  assert z <= z
  assert 1 <= y
  assert 3 <= y
Esempio n. 16
0
def test_lte():

    x = Bits(4, 0b1100)
    y = Bits(4, 0b0011)
    z = Bits(4, 0b0011)
    assert y.uint() <= x.uint()
    assert y.uint() <= 10
    assert y.uint() <= z.uint()
    assert y.uint() <= 0b0011
    assert y <= x.uint()
    assert y <= 10
    assert y <= z.uint()
    assert y <= 0b0011
    assert y <= x
    assert y <= z
    assert z <= x
    assert z <= z
    assert 1 <= y
    assert 3 <= y
Esempio n. 17
0
def test_gte():

  x = Bits( 4, 0b1100 )
  y = Bits( 4, 0b0011 )
  z = Bits( 4, 0b1100 )
  assert x.uint() >= y.uint()
  assert x.uint() >= 2
  assert x.uint() >= z.uint()
  assert x.uint() >= 0b1100
  assert x >= y.uint()
  assert x >= 2
  assert x >= z.uint()
  assert x >= 0b1100
  assert x >= y
  assert x >= z
  assert z >= y
  assert z >= x
  assert x >= x
  assert 5 >= y
  assert 3 <= y
Esempio n. 18
0
def test_gte():

    x = Bits(4, 0b1100)
    y = Bits(4, 0b0011)
    z = Bits(4, 0b1100)
    assert x.uint() >= y.uint()
    assert x.uint() >= 2
    assert x.uint() >= z.uint()
    assert x.uint() >= 0b1100
    assert x >= y.uint()
    assert x >= 2
    assert x >= z.uint()
    assert x >= 0b1100
    assert x >= y
    assert x >= z
    assert z >= y
    assert z >= x
    assert x >= x
    assert 5 >= y
    assert 3 <= y
Esempio n. 19
0
def test_eq():

    x = Bits(4, 0b1010)
    assert x.uint() == x.uint()
    # Compare objects by value, not id
    assert x == x
    # Check the value
    assert x.uint() == 0b1010
    assert x.uint() == 0xA
    assert x.uint() == 10
    # Checking the equality operator
    assert x == 0b1010
    assert x == 0xA
    assert x == 10
    # Checking comparison with another bit container
    y = Bits(4, 0b1010)
    assert x.uint() == y.uint()
    assert x == y
    y = Bits(8, 0b1010)
    assert x.uint() == y.uint()
    # TODO: How should equality between Bits objects work?
    #       Just same value or same value and width?
    #assert x == y
    # Check the negatives
    x = Bits(4, -1)
    assert x.uint() == 0b1111
    assert x.uint() == 0xF
    assert x.uint() == 15
    # Checking the equality operator
    assert x == 0b1111
    assert x == 0xF
    assert x == 15
    assert x.uint() == Bits(4, -1).uint()
    assert x == Bits(4, -1).uint()
    assert 15 == x

    assert not x == None
    assert not Bits(4, 0) == None
Esempio n. 20
0
def test_compare_uint_neg():

    x = Bits(4, 2)
    assert x.uint() != -1
    assert x.uint() > -1
    assert x.uint() >= -1
Esempio n. 21
0
def test_compare_uint_neg():

  x = Bits( 4, 2 )
  assert x.uint() != -1
  assert x.uint()  > -1
  assert x.uint() >= -1
Esempio n. 22
0
def test_eq():

  x = Bits( 4, 0b1010 )
  assert x.uint() == x.uint()
  # Compare objects by value, not id
  assert x == x
  # Check the value
  assert x.uint() == 0b1010
  assert x.uint() == 0xA
  assert x.uint() == 10
  # Checking the equality operator
  assert x == 0b1010
  assert x == 0xA
  assert x == 10
  # Checking comparison with another bit container
  y = Bits( 4, 0b1010 )
  assert x.uint() == y.uint()
  assert x == y
  y = Bits( 8 , 0b1010 )
  assert x.uint() == y.uint()
  # TODO: How should equality between Bits objects work?
  #       Just same value or same value and width?
  #assert x == y
  # Check the negatives
  x = Bits( 4, -1 )
  assert x.uint() == 0b1111
  assert x.uint() == 0xF
  assert x.uint() == 15
  # Checking the equality operator
  assert x == 0b1111
  assert x == 0xF
  assert x == 15
  assert x.uint() == Bits(4, -1).uint()
  assert x == Bits( 4, -1 ).uint()
  assert 15 == x

  assert not x == None
  assert not Bits( 4, 0 ) == None