How do you assert that an exception was thrown in JUnit 4 tests?

How to use JUnit 4 to test some code to throw exceptions? Although I can certainly do such things: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } I remember in this case, having a ...

Posted by ivki on Thu, 05 Dec 2019 07:17:29 -0800

Noseparte says: There's nothing less HashMap to make Java play well

Brief Introduction As a Java programmer, HashMap is an inevitable data type.This is evidenced by both the frequency of use in development and the frequency of inspection in interviews. HashMap's Past and Present HashMap was born in JDK1.2. With the update of JDK version and to solve hash collision problem in HashMap in JDK1.7,Oracle team at JE ...

Posted by Davo on Thu, 05 Dec 2019 05:14:39 -0800

Learn Bayesian inference from Earth throwing test

We know that about 70% of the earth is covered by water. If the earth is in your hands like a small ball now, you throw it into the sky. What is the probability that the point of touchdown is the water area? This document and code are from Here. Let's first assume that we don't know at all how much of the earth's area is covered b ...

Posted by mycro on Thu, 05 Dec 2019 05:02:21 -0800

Some built-in functions of python

Built in function mind map: https://www.processon.com/mindmap/5c10ca52e4b0c2ee256ac034 Built-in function Anonymous function The unified name of anonymous function is: < lambda > Usage scenario: used with sorted, map and filter   fn = lambda a, b : a + b # Define a very simple function. Do not use complex functions lambda ret = fn(3, 5) p ...

Posted by jimbob on Thu, 05 Dec 2019 01:16:29 -0800

pycharm's latest code, share it with you

The latest pycharm activation code, by November next year, a hardworking Python programmer In the past two days, I have been busy with the small projects arranged by the school, which are less updated for you. I will fill them up slowly and study hard at pycharm. If you have any questions, please ask me. I will try my best to help you answer th ...

Posted by Lillefix on Wed, 04 Dec 2019 21:14:46 -0800

Talk about using flexible and px2rem loader in Vue cli

1. Download lib flexible npm i lib-flexible --save //or yarn add lib-flexible 2. Introduce lib flexible in the project. Generally, introduce lib flexible in (main.js) import 'lib-flexible/flexible' 3. Set meta tag (as appropriate) <meta name="viewport" content="width=device-width, initial-scale=1.0"> 4. Install px2rem loader npm instal ...

Posted by pdpullmn612 on Wed, 04 Dec 2019 20:37:07 -0800

Program example (beginner)

Example 1: calculate the approximate value of π with the formula π / 4 = 1-1 / 3 + 1 / 5-1 / 7 +... Until the absolute value of a term is less than 10 ^ 6. Tips: (1) to determine the accuracy of the calculation, you can use the fabs() function with the while loop statement to determine the accuracy to exit. (2) it is observed that the num ...

Posted by sheila on Wed, 04 Dec 2019 18:11:06 -0800

LeetCode 98 -- verify binary search tree

1. topic 2. answers For a node, there are four situations: The node is empty or both left and right nodes of the node are empty; Only the right node is empty; Only the left node is empty; Left and right nodes are not empty; If the left and right sub nodes of the current node satisfy the condition of binary search tree, we can recursively jud ...

Posted by jpearson on Wed, 04 Dec 2019 17:51:31 -0800

Upload video and screenshot, cross domain error resolution

Reasons for cross domain error reporting After the video is uploaded successfully in the first place, the src of the video tag will directly introduce the resource address of the uploaded server, and then the cross domain error message will appear when using the canvas screenshot. Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted c ...

Posted by ThinkGeekness on Wed, 04 Dec 2019 17:27:40 -0800

Niuke network: Huawei 2016 R & D Engineer programming problem (C + +)

1, Delete number Time limit: 1 second Space limit: 32768K There is an array a[N] to store 0~N-1 in order. It is required to delete one number every two numbers. At the end of the array, cycle to the beginning to continue, and find the original subscript position of the last deleted number. Take 8 numbers (N=7) for example: ...

Posted by collette on Wed, 04 Dec 2019 17:19:13 -0800