How to use float_range method in hypothesis

Best Python code snippet using hypothesis

test_float_range.py

Source: test_float_range.py Github

copy

Full Screen

...4from float_range import float_range5class FloatRangeTests(unittest.TestCase):6 """Tests for float_range."""7 def test_has_iterability(self):8 self.assertEqual(list(float_range(1, 11, 2)), [1, 3, 5, 7, 9])9 self.assertEqual(10 list(float_range(0.5, 7, 0.75)),11 [0.5, 1.25, 2.0, 2.75, 3.5, 4.25, 5.0, 5.75, 6.5]12 )13 def test_optional_step(self):14 self.assertEqual(list(float_range(1, 6, 1)), [1, 2, 3, 4, 5])15 self.assertEqual(list(float_range(1, 6)), [1, 2, 3, 4, 5])16 self.assertEqual(17 list(float_range(0.5, 6)),18 [0.5, 1.5, 2.5, 3.5, 4.5, 5.5]19 )20 def test_optional_start(self):21 self.assertEqual(list(float_range(0, 6)), [0, 1, 2, 3, 4, 5])22 self.assertEqual(list(float_range(6)), [0, 1, 2, 3, 4, 5])23 self.assertEqual(24 list(float_range(4.2)),25 [0, 1, 2, 3, 4]26 )27 def test_fractional_step_size(self):28 self.assertEqual(29 list(float_range(1, 6, 0.5)),30 [1, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5]31 )32 self.assertEqual(33 list(float_range(1, 5.6, 0.5)),34 [1, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5]35 )36 def test_negative_step(self):37 with self.assertRaises(StopIteration):38 # Should be empty so StopIteration should be raised39 next(iter(float_range(1, 6, -1)))40 self.assertEqual(list(float_range(5, 0, -1)), [5, 4, 3, 2, 1])41 self.assertEqual(42 list(float_range(0.5, 6)),43 [0.5, 1.5, 2.5, 3.5, 4.5, 5.5]44 )45 self.assertEqual(46 list(float_range(6, 1, -0.5)),47 [6, 5.5, 5.0, 4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5]48 )49 def test_no_arguments(self):50 with self.assertRaises(TypeError):51 float_range()52 def test_too_many_arguments(self):53 with self.assertRaises(TypeError):54 float_range(0, 5, 1, 1)55 with self.assertRaises(TypeError):56 float_range(0, 5, 1, 1, 1)57 def test_no_memory_used(self):58 """Make sure float_range response isn't a giant list of numbers."""59 response = float_range(0, 1024, 2**-4)60 if isinstance(response, Generator):61 next(response)62 size = sum(63 sys.getsizeof(obj)64 for obj in response.gi_frame.f_locals.values()65 )66 else:67 size = sys.getsizeof(response)68 self.assertLess(size, 8000, 'Too much memory used')69 self.assertNotEqual(type(response), list)70 self.assertNotEqual(type(response), tuple)71 # @unittest.expectedFailure72 def test_has_length(self):73 self.assertEqual(len(float_range(100)), 100)74 self.assertEqual(len(float_range(1, 100)), 99)75 self.assertEqual(len(float_range(1, 11, 2)), 5)76 self.assertEqual(len(float_range(0.5, 7, 0.75)), 9)77 self.assertEqual(len(float_range(1000000)), 1000000)78 self.assertEqual(len(float_range(11, 1.2, -2)), 5)79 self.assertEqual(len(float_range(11, 1.2, 2)), 0)80 # @unittest.expectedFailure81 def test_reversed(self):82 r = reversed(float_range(0.5, 7, 0.75))83 self.assertEqual(84 list(r),85 [6.5, 5.75, 5.0, 4.25, 3.5, 2.75, 2.0, 1.25, 0.5]86 )87 big_num = 100000088 self.assertEqual(next(reversed(float_range(big_num))), big_num-1)89 # @unittest.expectedFailure90 def test_equality(self):91 self.assertEqual(float_range(0, 5, 0.5), float_range(0, 5, 0.5))92 self.assertEqual(float_range(5, 5), float_range(10, 10))93 self.assertEqual(float_range(5, 11, 5), float_range(5, 12, 5))94 self.assertEqual(float_range(10), float_range(0, 10))95 self.assertNotEqual(96 float_range(0, 2**10, 2**-10),97 float_range(0, 2**10+1, 2**-10),98 )99 self.assertEqual(float_range(1000000), range(1000000))100 self.assertEqual(range(1000000), float_range(1000000))101 self.assertFalse(float_range(0, 5, 0.5) != float_range(0, 5, 0.5))102 class EqualToEverything:103 def __eq__(self, other):104 return True105 self.assertEqual(float_range(1000000), EqualToEverything())106if __name__ == "__main__":...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Appium Testing Tutorial For Mobile Applications

The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.

Options for Manual Test Case Development & Management

The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.

How To Get Started With Cypress Debugging

One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.

Get A Seamless Digital Experience With #LambdaTestYourBusiness????

The holidays are just around the corner, and with Christmas and New Year celebrations coming up, everyone is busy preparing for the festivities! And during this busy time of year, LambdaTest also prepped something special for our beloved developers and testers – #LambdaTestYourBusiness

Dec’22 Updates: The All-New LT Browser 2.0, XCUI App Automation with HyperExecute, And More!

Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful