# Path: offset/sync/atomic.py
# class AtomicLong(object):
#     def __init__(self, initial_value):
#     def __repr__(self):
#     def value(self):
#     def value(self, new):
#     def add(self, delta):
#     def __iadd__(self, inc):
#     def __isub__(self, dec):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):


from offset.sync.atomic import AtomicLong, ffi, lib
# -*- coding: utf-8 -
#
# This file is part of offset. See the NOTICE for more information.
# copyright (c) 2013 David Reid under the MIT License.



def test_long_add_and_fetch():
    l = ffi.new('long *', 0)
    assert lib.long_add_and_fetch(l, 1) == 1
    assert lib.long_add_and_fetch(l, 10) == 11

def test_long_sub_and_fetch():
    l = ffi.new('long *', 0)
    assert lib.long_sub_and_fetch(l, 1) == -1
    assert lib.long_sub_and_fetch(l, 10) == -11

def test_long_bool_compare_and_swap():
    l = ffi.new('long *', 0)
    assert lib.long_bool_compare_and_swap(l, 0, 10) == True

# Path: offset/sync/atomic.py
# class AtomicLong(object):
#     def __init__(self, initial_value):
#     def __repr__(self):
#     def value(self):
#     def value(self, new):
#     def add(self, delta):
#     def __iadd__(self, inc):
#     def __isub__(self, dec):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __lt__(self, other):


# Path: tests/test_atomic.py
from offset.sync.atomic import AtomicLong, ffi, lib

# -*- coding: utf-8 -
#
# This file is part of offset. See the NOTICE for more information.
# copyright (c) 2013 David Reid under the MIT License.



def test_long_add_and_fetch():
    l = ffi.new('long *', 0)
    assert lib.long_add_and_fetch(l, 1) == 1
    assert lib.long_add_and_fetch(l, 10) == 11

def test_long_sub_and_fetch():
    l = ffi.new('long *', 0)
    assert lib.long_sub_and_fetch(l, 1) == -1
    assert lib.long_sub_and_fetch(l, 10) == -11

def test_long_bool_compare_and_swap():
    l = ffi.new('long *', 0)
    assert lib.long_bool_compare_and_swap(l, 0, 10) == True

    assert lib.long_bool_compare_and_swap(l, 1, 20) == False