# Path: mirror/queue.py
# class TaskInfo():
#     def __init__(self, name, tasktype, time, priority):
#         self.name     = name
#         self.tasktype = tasktype
#         self.time     = time
#         self.priority = priority
# 
#     def __eq__(self, other):
#         return self.name == other.name
# 
#     def __lt__(self, other):
#         return (self.time - other.time < 0) if self.time != other.time else (
#                                            self.priority - other.priority < 0)
# 
#     def __cmp__(self, other):
#         return (self.time - other.time) if self.time != other.time else (
#                                            self.priority - other.priority)
# 
#     def __str__(self):
#         return "(name: %s, type: %d, time: %d, priority: %d)" % (self.name,
#                                     self.tasktype, self.time, self.priority)
# 
# Path: mirror/queue.py
# class Queue(object):
#     def __init__(self, *items):
#         self.queue = []
#         for item in items:
#             if not isinstance(item, TaskInfo):
#                 continue
#             self.put(item)
# 
#     def put(self, item):
#         bisect.insort(self.queue, item)
# 
#     def get(self):
#         try:
#             return self.queue.pop(0)
#         except:
#             return None
# 
#     def remove(self, item):
#         self.queue.remove(item)
# 
#     def empty(self):
#         return ( len(self.queue) == 0 )
# 
#     def size(self, key = None, value = None):
#         if key is None or value is None:
#             return len(self.queue)
#         else:
#             if self.empty():
#                 return 0
#             if not hasattr(self.queue[0], key):
#                 return 0
#             count = 0
#             for item in self.queue:
#                 count += ( getattr(item, key) == value )
#             return count
# 
#     def find(self, name):
#         for taskinfo in self.queue:
#             if taskinfo.name == name:
#                 return taskinfo
#         return None
# 
#     def __getitem__(self, key):
#         try:
#             return self.queue[key]
#         except:
#             return None
# 
#     def __str__(self):
#         return "[" + ",".join([str(item) for item in self.queue]) + "]"
# 
#     def __iter__(self):
#         for item in self.queue:
#             yield item
# 
#     def __contains__(self, item):
#         return item in self.queue


import unittest
from mirror.queue import TaskInfo
from mirror.queue import Queue
#
# Copyright (C) 2014 Shang Yuanchun <idealities@gmail.com>
#
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# mirror is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mirror. If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#



class TaskQueueTestCase(unittest.TestCase):

    def test_taskqueue(self):
        task1 = TaskInfo("Buy clock",    0, 1376712000, 2)

# Path: mirror/queue.py
# class TaskInfo():
#     def __init__(self, name, tasktype, time, priority):
#         self.name     = name
#         self.tasktype = tasktype
#         self.time     = time
#         self.priority = priority
# 
#     def __eq__(self, other):
#         return self.name == other.name
# 
#     def __lt__(self, other):
#         return (self.time - other.time < 0) if self.time != other.time else (
#                                            self.priority - other.priority < 0)
# 
#     def __cmp__(self, other):
#         return (self.time - other.time) if self.time != other.time else (
#                                            self.priority - other.priority)
# 
#     def __str__(self):
#         return "(name: %s, type: %d, time: %d, priority: %d)" % (self.name,
#                                     self.tasktype, self.time, self.priority)
# 
# Path: mirror/queue.py
# class Queue(object):
#     def __init__(self, *items):
#         self.queue = []
#         for item in items:
#             if not isinstance(item, TaskInfo):
#                 continue
#             self.put(item)
# 
#     def put(self, item):
#         bisect.insort(self.queue, item)
# 
#     def get(self):
#         try:
#             return self.queue.pop(0)
#         except:
#             return None
# 
#     def remove(self, item):
#         self.queue.remove(item)
# 
#     def empty(self):
#         return ( len(self.queue) == 0 )
# 
#     def size(self, key = None, value = None):
#         if key is None or value is None:
#             return len(self.queue)
#         else:
#             if self.empty():
#                 return 0
#             if not hasattr(self.queue[0], key):
#                 return 0
#             count = 0
#             for item in self.queue:
#                 count += ( getattr(item, key) == value )
#             return count
# 
#     def find(self, name):
#         for taskinfo in self.queue:
#             if taskinfo.name == name:
#                 return taskinfo
#         return None
# 
#     def __getitem__(self, key):
#         try:
#             return self.queue[key]
#         except:
#             return None
# 
#     def __str__(self):
#         return "[" + ",".join([str(item) for item in self.queue]) + "]"
# 
#     def __iter__(self):
#         for item in self.queue:
#             yield item
# 
#     def __contains__(self, item):
#         return item in self.queue


# Path: test/test_taskqueue.py
import unittest
from mirror.queue import TaskInfo
from mirror.queue import Queue

#
# Copyright (C) 2014 Shang Yuanchun <idealities@gmail.com>
#
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# mirror is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mirror. If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#



class TaskQueueTestCase(unittest.TestCase):

    def test_taskqueue(self):
        task1 = TaskInfo("Buy clock",    0, 1376712000, 2)

        task2 = TaskInfo("Basketball",   0, 1376701200, 1)