# Path: tests/search/dummies.py
# class DummyNode(object):
#     def __init__(self, value):
#         self.value = value
# 
#     def __lt__(self, other):
#         return self.value < other.value
# 
# Path: simpleai/search/utils.py
# class FifoList(deque):
#     '''List that pops from the beginning.'''
#     def pop(self):
#         return super(FifoList, self).popleft()
# 
#     def sorted(self):
#         return list(self)
# 
# class BoundedPriorityQueue(object):
#     def __init__(self, limit=None, *args):
#         self.limit = limit
#         self.queue = list()
# 
#     def __getitem__(self, val):
#         return self.queue[val]
# 
#     def __len__(self):
#         return len(self.queue)
# 
#     def append(self, x):
#         heapq.heappush(self.queue, x)
#         if self.limit and len(self.queue) > self.limit:
#             self.queue.remove(heapq.nlargest(1, self.queue)[0])
#             heapq.heapify(self.queue)
# 
#     def pop(self):
#         return heapq.heappop(self.queue)
# 
#     def extend(self, iterable):
#         for x in iterable:
#             self.append(x)
# 
#     def clear(self):
#         self.queue.clear()
# 
#     def remove(self, x):
#         self.queue.remove(x)
#         heapq.heapify(self.queue)
# 
#     def sorted(self):
#         return heapq.nsmallest(len(self.queue), self.queue)
# 
# class LifoList(deque):
#     '''List that pops from the end.'''
# 
#     def sorted(self):
#         return list(self)[::-1]
# 
# def argmax(iterable, function):
#     return _generic_arg(iterable, function, max)
# 
# def argmin(iterable, function):
#     return _generic_arg(iterable, function, min)


import unittest
from tests.search.dummies import DummyNode
from simpleai.search.utils import FifoList, BoundedPriorityQueue, LifoList, argmax, argmin

    def test_return_max(self):
        self.assertEqual('a', argmax(['a', 'b'], lambda x: self.d[x]))

    def test_random_tie(self):
        a = 0
        for x in range(100):
            if argmax(['a', 'b', 'c'], lambda x: self.d[x]) == 'a':
                a += 1
        self.assertTrue(25 < a < 75)

    def test_empty_sequence(self):
        self.assertRaises(ValueError, argmax, [], lambda x: x)


class TestArgMin(unittest.TestCase):
    def setUp(self):
        self.d = {'a': 1, 'b': 1, 'c': 3}

    def test_return_max(self):
        self.assertEqual('b', argmin(['c', 'b'], lambda x: self.d[x]))

    def test_random_tie(self):
        a = 0
        for x in range(100):
            if argmin(['a', 'b', 'c'], lambda x: self.d[x]) == 'a':
                a += 1
        self.assertTrue(25 < a < 75)

    def test_empty_sequence(self):

# Path: tests/search/dummies.py
# class DummyNode(object):
#     def __init__(self, value):
#         self.value = value
# 
#     def __lt__(self, other):
#         return self.value < other.value
# 
# Path: simpleai/search/utils.py
# class FifoList(deque):
#     '''List that pops from the beginning.'''
#     def pop(self):
#         return super(FifoList, self).popleft()
# 
#     def sorted(self):
#         return list(self)
# 
# class BoundedPriorityQueue(object):
#     def __init__(self, limit=None, *args):
#         self.limit = limit
#         self.queue = list()
# 
#     def __getitem__(self, val):
#         return self.queue[val]
# 
#     def __len__(self):
#         return len(self.queue)
# 
#     def append(self, x):
#         heapq.heappush(self.queue, x)
#         if self.limit and len(self.queue) > self.limit:
#             self.queue.remove(heapq.nlargest(1, self.queue)[0])
#             heapq.heapify(self.queue)
# 
#     def pop(self):
#         return heapq.heappop(self.queue)
# 
#     def extend(self, iterable):
#         for x in iterable:
#             self.append(x)
# 
#     def clear(self):
#         self.queue.clear()
# 
#     def remove(self, x):
#         self.queue.remove(x)
#         heapq.heapify(self.queue)
# 
#     def sorted(self):
#         return heapq.nsmallest(len(self.queue), self.queue)
# 
# class LifoList(deque):
#     '''List that pops from the end.'''
# 
#     def sorted(self):
#         return list(self)[::-1]
# 
# def argmax(iterable, function):
#     return _generic_arg(iterable, function, max)
# 
# def argmin(iterable, function):
#     return _generic_arg(iterable, function, min)


# Path: tests/search/test_utils.py
import unittest
from tests.search.dummies import DummyNode
from simpleai.search.utils import FifoList, BoundedPriorityQueue, LifoList, argmax, argmin


    def test_return_max(self):
        self.assertEqual('a', argmax(['a', 'b'], lambda x: self.d[x]))

    def test_random_tie(self):
        a = 0
        for x in range(100):
            if argmax(['a', 'b', 'c'], lambda x: self.d[x]) == 'a':
                a += 1
        self.assertTrue(25 < a < 75)

    def test_empty_sequence(self):
        self.assertRaises(ValueError, argmax, [], lambda x: x)


class TestArgMin(unittest.TestCase):
    def setUp(self):
        self.d = {'a': 1, 'b': 1, 'c': 3}

    def test_return_max(self):
        self.assertEqual('b', argmin(['c', 'b'], lambda x: self.d[x]))

    def test_random_tie(self):
        a = 0
        for x in range(100):
            if argmin(['a', 'b', 'c'], lambda x: self.d[x]) == 'a':
                a += 1
        self.assertTrue(25 < a < 75)

    def test_empty_sequence(self):

        self.assertRaises(ValueError, argmin, [], lambda x: x)