mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Revert changes for #13355 by request from Raymond Hettinger
This commit is contained in:
		
						commit
						44e33f39bf
					
				
					 4 changed files with 1 additions and 42 deletions
				
			
		|  | @ -345,16 +345,6 @@ def triangular(self, low=0.0, high=1.0, mode=None): | ||||||
|         http://en.wikipedia.org/wiki/Triangular_distribution |         http://en.wikipedia.org/wiki/Triangular_distribution | ||||||
| 
 | 
 | ||||||
|         """ |         """ | ||||||
|         # Sanity check. According to the doc low must be less or equal to |  | ||||||
|         # high. And mode should be somewhere between these bounds. |  | ||||||
|         if low > high: |  | ||||||
|             raise ValueError('high cannot be less then low.') |  | ||||||
|         if mode is not None and (mode < low or mode > high): |  | ||||||
|             raise ValueError('mode must be between low and high.') |  | ||||||
| 
 |  | ||||||
|         if high == low: |  | ||||||
|             return low |  | ||||||
| 
 |  | ||||||
|         u = self.random() |         u = self.random() | ||||||
|         c = 0.5 if mode is None else (mode - low) / (high - low) |         c = 0.5 if mode is None else (mode - low) / (high - low) | ||||||
|         if u > c: |         if u > c: | ||||||
|  |  | ||||||
|  | @ -48,33 +48,6 @@ def __hash__(self): | ||||||
|         self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4) |         self.assertRaises(TypeError, self.gen.seed, 1, 2, 3, 4) | ||||||
|         self.assertRaises(TypeError, type(self.gen), []) |         self.assertRaises(TypeError, type(self.gen), []) | ||||||
| 
 | 
 | ||||||
|     def test_triangular(self): |  | ||||||
|         # Check that triangular() correctly handles bad input. See issue 13355. |  | ||||||
|         # mode > high. |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(mode=2) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=1, high=10, mode=11) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=1, high=1, mode=11) |  | ||||||
|         # mode < low. |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(mode=-1) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=1, high=10, mode=0) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=1, high=1, mode=0) |  | ||||||
|         # low > high |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=5, high=2) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=5, high=2, mode=1) |  | ||||||
|         with self.assertRaises(ValueError): |  | ||||||
|             random.triangular(low=-2, high=-5) |  | ||||||
| 
 |  | ||||||
|         self.assertEqual(random.triangular(low=10, high=10), 10) |  | ||||||
|         self.assertEqual(random.triangular(low=10, high=10, mode=10), 10) |  | ||||||
| 
 |  | ||||||
|     @unittest.mock.patch('random._urandom') # os.urandom |     @unittest.mock.patch('random._urandom') # os.urandom | ||||||
|     def test_seed_when_randomness_source_not_found(self, urandom_mock): |     def test_seed_when_randomness_source_not_found(self, urandom_mock): | ||||||
|         # Random.seed() uses time.time() when an operating system specific |         # Random.seed() uses time.time() when an operating system specific | ||||||
|  | @ -623,7 +596,7 @@ def test_constant(self): | ||||||
|         for variate, args, expected in [ |         for variate, args, expected in [ | ||||||
|                 (g.uniform, (10.0, 10.0), 10.0), |                 (g.uniform, (10.0, 10.0), 10.0), | ||||||
|                 (g.triangular, (10.0, 10.0), 10.0), |                 (g.triangular, (10.0, 10.0), 10.0), | ||||||
|                 (g.triangular, (10.0, 10.0, 10.0), 10.0), |                 #(g.triangular, (10.0, 10.0, 10.0), 10.0), | ||||||
|                 (g.expovariate, (float('inf'),), 0.0), |                 (g.expovariate, (float('inf'),), 0.0), | ||||||
|                 (g.vonmisesvariate, (3.0, float('inf')), 3.0), |                 (g.vonmisesvariate, (3.0, float('inf')), 3.0), | ||||||
|                 (g.gauss, (10.0, 0.0), 10.0), |                 (g.gauss, (10.0, 0.0), 10.0), | ||||||
|  |  | ||||||
|  | @ -1110,7 +1110,6 @@ Nick Seidenman | ||||||
| Žiga Seilnacht | Žiga Seilnacht | ||||||
| Yury Selivanov | Yury Selivanov | ||||||
| Fred Sells | Fred Sells | ||||||
| Yuriy Senko |  | ||||||
| Jiwon Seo | Jiwon Seo | ||||||
| Iñigo Serna | Iñigo Serna | ||||||
| Joakim Sernbrant | Joakim Sernbrant | ||||||
|  |  | ||||||
|  | @ -39,9 +39,6 @@ Core and Builtins | ||||||
| Library | Library | ||||||
| ------- | ------- | ||||||
| 
 | 
 | ||||||
| - Issue #13355: Raise ValueError on random.triangular call with invalid params. |  | ||||||
|   Initial patch by Yuriy Senko. |  | ||||||
| 
 |  | ||||||
| - Issue #16658: add missing return to HTTPConnection.send() | - Issue #16658: add missing return to HTTPConnection.send() | ||||||
|   Patch by Jeff Knupp. |   Patch by Jeff Knupp. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Svetlov
						Andrew Svetlov