tests/app/soc/logic/test_allocations.py
author Mario Ferraro <fadinlight@gmail.com>
Sun, 15 Nov 2009 22:12:20 +0100
changeset 3093 d1be59b6b627
parent 2142 573301607587
permissions -rw-r--r--
GMaps related JS changed to use new google namespace. Google is going to change permanently in the future the way to load its services, so better stay safe. Also this commit shows uses of the new melange.js module. Fixes Issue 634.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1056
diff changeset
     3
# Copyright 2009 the Melange authors.
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
__authors__ = [
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  ]
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
import unittest
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from soc.logic import allocations
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
class Student(object):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
  """Mocker for Student object.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
  """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
  def __init__(self, id):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
    """Simple init that stores id for later use.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
    self.id = id
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
  def __eq__(self, other):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
    """Simple eq that compares ids.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
    return self.id == other.id
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  def __str__(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    """Simple str that returns str(id).
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
    return str(self.id)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
  def __repr__(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
    """Simple repr that returns repr(id).
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
    return repr(self.id)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
class AllocationsTest(unittest.TestCase):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
  """Tests related to the slot allocation algorithm.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
  def setUp(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
    """Set up required for the slot allocation tests.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
    self.slots = 60
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
    self.max_slots_per_org = 40
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    67
    self.min_slots_per_org = 2
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
    self.allocated = 0
2140
32b0731f0bf5 Add a new allocation algorithm and use it
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2139
diff changeset
    69
    self.algorithm = 2
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    70
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    71
    apps = {
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    72
        'asf': (20, 20),
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    73
        'gcc': (15, 50),
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    74
        'git': (6, 6),
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    75
        'google': (3, 10),
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    76
        'melange': (100, 3),
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
        }
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    78
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    79
    self.popularity = dict([(k,a) for k, (a, m) in apps.iteritems()])
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    80
    self.mentors = dict([(k,m) for k, (a, m) in apps.iteritems()])
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    81
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    82
    self.orgs = self.popularity.keys()
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    83
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    84
    self.allocater = allocations.Allocator(
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
    85
        self.orgs, self.popularity, self.mentors, self.slots,
2139
43a02512ebf7 Change iterative to algorithm in slot allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2130
diff changeset
    86
        self.max_slots_per_org, self.min_slots_per_org, self.algorithm)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    88
  def testInitialAllocation(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    89
    """Test that an allocation with no arguments does not crash.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    91
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
    locked_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    93
    adjusted_slots = {}
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
    94
    self.allocater.allocate(locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    95
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
  def testLockedSlotsAllocation(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    97
    """Test that an allocation with an org locked does not crash.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    98
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    99
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   100
    locked_slots = {'melange': 3}
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   101
    self.allocater.allocate(locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   103
  def testNonExistantOrgAllocation(self):
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
    """Test that locking a non-existing org errors out.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   106
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   107
    locked_slots = {'gnome': 1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   109
                          locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
  def testInitialAllocationBelowMaxSlots(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
    """Test that the initial allocation is below the max slot count.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   114
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   115
    locked_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   117
    result = self.allocater.allocate(locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
    self.failIf(sum(result.values()) > self.slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
  def testLockedAllocationCorrect(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
    """Test that locking an allocation assigns the org the allocation.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
    locked_slots = {'git': 6}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   126
    result = self.allocater.allocate(locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
    expected = 6
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
    actual = result['git']
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
    self.failUnlessEqual(expected, actual)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   132
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   133
  def testOverassignedAllocationCorrect(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
    """Test that over-assigned allocation are cut down.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
    locked_slots = {'git': 20}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
2130
83f4fab7c556 Drop the 'adjustement' part of slots allocation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1751
diff changeset
   139
    result = self.allocater.allocate(locked_slots)
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   141
    expected = 6
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
    actual = result['git']
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
    self.failUnlessEqual(expected, actual)
2142
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   145
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   146
  def testAllOrgsLocked(self):
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   147
    """Test that when all orgs are locked the correct result is given.
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   148
    """
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   149
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   150
    locked_slots = {
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   151
        'asf': 20,
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   152
        'gcc': 15,
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   153
        'git': 6,
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   154
        'google': 3,
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   155
        'melange': 3,
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   156
        }
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   157
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   158
    result = self.allocater.allocate(locked_slots)
573301607587 Add a test case to demonstrate a bug in the allocator
Sverre Rabbelier <srabbelier@gmail.com>
parents: 2140
diff changeset
   159
    self.failUnlessEqual(locked_slots, result)