I have a list of input, a greedy method and a dynamic programming method. I wrote a unittest script to test my two methods with input list but I don't know if I'm writing it right:
import unittest
from land_selling import Offer, Seller
class LandSellingTest(unittest.TestCase):
offers1 = [
Offer(0, 6, 2),
Offer(1, 2, 4),
Offer(3, 5, 1),
Offer(5, 9, 3),
Offer(7, 10, 2),
Offer(10, 20, 5),
Offer(34, 2, 1)
]
offers2 = [
Offer(6, 10, 4),
Offer(1, 5, 2),
Offer(7, 20, 3),
Offer(2, 7, 1),
Offer(14, 30, 2),
Offer(3, 6, 3),
Offer(8, 15, 2),
Offer(20, 35, 5),
Offer(25, 5, 3)
]
offers3 = [
Offer(17, 1, 12),
Offer(7, 2, 10),
Offer(17, 2, 8),
Offer(20, 3, 6),
Offer(3, 11, 4),
Offer(22, 12, 2)
]
// input list
global offers_list
offers_list = [offers1, offers2, offers3]
// greedy output list
global greedy_answers
greedy_answers = [4, 3, 2]
// dynamic output list
global dynamic_answers
dynamic_answers = [13, 12, 16]
@classmethod
def setUpClass(self):
self.offers_list = offers_list
self.greedy_answers = greedy_answers
self.dynamic_answers = dynamic_answers
def test_greedy(self):
for offers, ans in zip(self.offers_list, self.greedy_answers):
seller = Seller(offers)
seller.set_up()
self.assertEqual(len(seller.accepted_offers()), ans)
def test_dynamic(self):
for offers, ans in zip(self.offers_list,self.dynamic_answers):
seller = Seller(offers)
seller.sort_offers_by_finish()
self.assertEqual(seller.maximum_profit(), ans)
if __name__ == '__main__':
unittest.main()