コード例 #1
0
 def test_unit_elasticity(self):
     elastic = ElasticOfDemand(start_price=4,
                               end_price=3,
                               start_demand=4,
                               end_demand=5)
     demand_type, _ = elastic.by_price()
     self.assertEqual(demand_type, DemandTypes.UnitElasticity)
コード例 #2
0
 def test_luxury(self):
     elastic = ElasticOfDemand(start_demand=10,
                               end_demand=13,
                               start_salary=500,
                               end_salary=600)
     demand_type, _ = elastic.by_salary()
     self.assertEqual(demand_type, DemandTypes.Luxury)
コード例 #3
0
 def test_elastic(self):
     elastic = ElasticOfDemand(start_price=5,
                               end_price=4,
                               start_demand=5,
                               end_demand=10)
     demand_type, _ = elastic.by_price()
     self.assertEqual(demand_type, DemandTypes.Elastic)
コード例 #4
0
 def test_lowquality(self):
     elastic = ElasticOfDemand(start_demand=200,
                               end_demand=180,
                               start_salary=500,
                               end_salary=600)
     demand_type, _ = elastic.by_salary()
     self.assertEqual(demand_type, DemandTypes.Lowquality)
コード例 #5
0
 def test_raise_with_not_init_salary(self):
     elastic = ElasticOfDemand(start_demand=4,
                               end_demand=5,
                               start_price=2,
                               end_price=1)
     with self.assertRaises(InvalidArgumentError):
         elastic.by_salary()
コード例 #6
0
 def test_essential(self):
     elastic = ElasticOfDemand(start_demand=50,
                               end_demand=53,
                               start_salary=500,
                               end_salary=600)
     demand_type, _ = elastic.by_salary()
     self.assertEqual(demand_type, DemandTypes.Essential)
 def calc_by_price(self):
     sd = int(
         split(r'\n',
               self.start_demand)[0]) if self.start_demand != '\n' else None
     ed = int(split(
         r'\n', self.end_demand)[0]) if self.end_demand != '\n' else None
     sp = int(split(
         r'\n', self.start_price)[0]) if self.start_price != '\n' else None
     ep = int(split(r'\n',
                    self.end_price)[0]) if self.end_price != '\n' else None
     self.logger.log(
         'Calculating elastic of demand by price. Args: %s, %s, %s, %s' %
         (sd, ed, sp, ep))
     demand = ElasticOfDemand(start_demand=sd,
                              end_demand=ed,
                              start_price=sp,
                              end_price=ep)
     self.type_price, _ = demand.by_price()
 def calc_by_salary(self):
     sd = int(
         split(r'\n',
               self.start_demand)[0]) if self.start_demand != '\n' else None
     ed = int(split(
         r'\n', self.end_demand)[0]) if self.end_demand != '\n' else None
     ss = int(
         split(r'\n',
               self.start_salary)[0]) if self.start_salary != '\n' else None
     es = int(split(
         r'\n', self.end_salary)[0]) if self.end_salary != '\n' else None
     self.logger.log(
         'Calculating elastic of demand by salary. Args: %s, %s, %s, %s' %
         (sd, ed, ss, es))
     demand = ElasticOfDemand(start_demand=sd,
                              end_demand=ed,
                              start_salary=ss,
                              end_salary=es)
     self.type_salary, _ = demand.by_salary()
コード例 #9
0
 def test_raise_init_with_zero_demand(self):
     with self.assertRaises(InvalidArgumentError):
         ElasticOfDemand(start_price=4,
                         end_price=3,
                         start_demand=0,
                         end_demand=2)
コード例 #10
0
 def test_raise_with_invalid_delta_price(self):
     with self.assertRaises(InvalidArgumentError):
         ElasticOfDemand(start_price=4,
                         end_price=5,
                         start_demand=4,
                         end_demand=6)
コード例 #11
0
 def test_raise_init_with_zero_delta_salary(self):
     with self.assertRaises(InvalidArgumentError):
         ElasticOfDemand(start_demand=4,
                         end_demand=5,
                         start_salary=1,
                         end_salary=1)