tests/app/soc/logic/test_allocations.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 08 Mar 2009 16:26:17 +0000
changeset 1751 17c7a7a48dc7
parent 1721 9acf4fe1b9bb
child 2130 83f4fab7c556
permissions -rw-r--r--
Switch from actual applications to popularity Patch by: Sverre Rabbelier
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
1718
ca34f4a8c61b Added an pre-processing algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1717
diff changeset
    69
    self.iterative = False
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,
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    86
        self.max_slots_per_org, self.min_slots_per_org, self.iterative)
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 = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
    self.allocater.allocate(locked_slots, adjusted_slots)
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}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   101
    adjusted_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   102
    self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   103
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   104
  def testAdjustedSlotsAllocation(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   105
    """Test that an allocation with an org adjusted does not crash.
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
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   108
    locked_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   109
    adjusted_slots = {'google': -1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   110
    self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   111
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   112
  def testInvalidSlotsAllocation(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   113
    """Test that an allocation with an org locked and adjusted errors out.
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
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
    locked_slots = {'git': 1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   117
    adjusted_slots = {'git': 1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
                          locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
  def testNonExistantOrgAllocation1(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
    """Test that locking a non-existing org errors out.
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
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
    locked_slots = {'gnome': 1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
    adjusted_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   128
                          locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   129
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   130
  def testNonExistantOrgAllocation2(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   131
    """Test that adjusting a non-existing org errors out.
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
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   134
    locked_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   135
    adjusted_slots = {'gnome': 1}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   136
    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   137
                          locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   138
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   139
  def testInitialAllocationBelowMaxSlots(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   140
    """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
   141
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   142
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   143
    locked_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   144
    adjusted_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   145
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   146
    result = self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   147
    self.failIf(sum(result.values()) > self.slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   148
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   149
  def testLockedAllocationCorrect(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   150
    """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
   151
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   152
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   153
    locked_slots = {'git': 6}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   154
    adjusted_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   155
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
    result = self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
    expected = 6
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    actual = result['git']
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
    self.failUnlessEqual(expected, actual)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   162
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   163
  def testOverassignedAllocationCorrect(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   164
    """Test that over-assigned allocation are cut down.
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   165
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   166
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   167
    locked_slots = {'git': 20}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   168
    adjusted_slots = {}
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   169
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   170
    result = self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   171
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   172
    expected = 6
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   173
    actual = result['git']
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   174
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   175
    self.failUnlessEqual(expected, actual)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   176
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   177
  def testAdjustedAllocationCorrect(self):
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   178
    """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
   179
    """
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   180
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   181
    locked_slots = {}
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   182
    adjusted_slots = {'gcc': 10}
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   183
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   184
    with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   185
    without_adjusting = self.allocater.allocate(locked_slots, {})
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   186
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
   187
    expected = without_adjusting['gcc'] + 10
1717
d4c4c8668871 Added assigned mentors and amount of minimum slots per org
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   188
    actual = with_adjusting['gcc']
1056
d0c82bdc2de2 Added a simple slot allocation algorithm
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   189
1751
17c7a7a48dc7 Switch from actual applications to popularity
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1721
diff changeset
   190
    self.failIf(actual < expected, "%d < %d" % (actual, expected))