I had an onCampus recruitement test of Goldman Sachs on HackerRank. I passed the given test cases but wanted to know if there are more test cases on the backend aur they evaluate through given test cases itself?
Tag: cases
Should Reduce give all cases when $\sqrt{x y} = \sqrt x \sqrt y$?
My understanding is that Reduce
gives all conditions (using or) where the input is true.
Now, $ \sqrt{xy} = \sqrt x \sqrt y $ , where $ x,y$ are real, under the following three conditions/cases
$ $ \begin{align*} x\geq 0,y\geq0\ x\geq0,y\leq0\ x\leq0,y\geq 0 \ \end{align*} $ $
but not when $ x<0,y<0$
This is verified by doing
ClearAll[x,y] Assuming[Element[{x,y},Reals]&&x>= 0&&y<= 0,Simplify[ Sqrt[x*y]  Sqrt[x]*Sqrt[y]]] Assuming[Element[{x,y},Reals]&&x<= 0&&y>= 0,Simplify[ Sqrt[x*y]  Sqrt[x]*Sqrt[y]]] Assuming[Element[{x,y},Reals]&&x<= 0&&y>= 0,Simplify[ Sqrt[x*y]  Sqrt[x]*Sqrt[y]]] Assuming[Element[{x,y},Reals]&&x<= 0&&y<= 0,Simplify[ Sqrt[x*y]  Sqrt[x]*Sqrt[y]]]
Then why does
Reduce[ Sqrt[x*y]  Sqrt[x]*Sqrt[y]==0,{x,y},Reals]
Give only one of the 3 cases above?
Is my understanding of Reduce
wrong or should Reduce
have given the other two cases?
V 12 on windows.
Cases where permanent and perfect matching and weighted perfect matching is easy?
Permanent of bounded rank matrix is in P by Barvinok. Permanent of bipartite planar biadjacency is in P by FKT.

How about number of perfect matchings for general planar graphs?

How about permanent of weighted biadjacency of bipartite graphs?
Some specific cases for binomial(n, k) when gcd(n, k)=1 or gcd(n, k)>1
I was programming the AKS primality test, and I have some questions.
If
gcd(n, k)==1, than binomial(n, k)=0 (mod n)
and
gcd(n, k)>1, than binomial(n, k)>0 (mod n)
Does this is correct?
NP problem algorithm that can solve more than normal algorithms,will it be P=NP for some cases or limiter?
assume that all algorithms can find optimum in problem like travel selesman problem for 25 cities which mean 25! possibility in polynomial time with using power of supercomputer then if there algorithm that can solve for 50 cities which mean 50! possibility with using power of supercomputer this mean it could to close range of many possibility to small number that could solve by like 25 cities
so what this algorithm mean ,p=np in limit of 50 cities, or just it can get answer under limit but it can not solve higher numbers like 100! although it could throw big number of possibility from 100!
Java: How do I read integer from the standard input, while handling error cases in a sophisticated way?
I want to read a simple integer from the console. But what if the user enters a string instead of an integer? How should I handle this case in a good manner? This is my code:
public static void main( String[] args ) { Scanner keyboard = new Scanner(System.in); System.out.println( "Please, enter the number of orders: " ); int orders = 1; if (keyboard.hasNextInt()) { orders = keyboard.nextInt() ; } else { System.out.println("Sorry, couldn't understand you!"); } }
Obviously it works, bit I am concerned that this solution was posted in 2010… is there a better way to handle such situation?
Nonalphanumeric variable names to clarify test cases
In a test I have many lines that look somewhat like this
foo should equal(Seq(true, false, false, true, false, false)) bar should equal(Seq(false, true, false, true, false, false)) baz should equal(Seq(false, false, false, true, true, false))
I find the expectations hard to distinguish. So I thought about doing it like this:
val ✔ = true val ✕ = false foo should equal(Seq(✔, ✕, ✕, ✔, ✕, ✕)) bar should equal(Seq(✕, ✔, ✕, ✕, ✔, ✕)) baz should equal(Seq(✕, ✕, ✔, ✕, ✕, ✔))
I presume using nonalphanumeric characters in code is usually frowned upon, but what if this is used to more clearly communicate a test case, such as above? Does the benefit outweigh the cost?
Is a language whose Turing Machine doesn’t halt for some positive cases but for others does not recursive?
Say language $ L$ is recursively enumerable, but not recursive. Say $ a$ and $ b$ are symbols of the alphabet and $ w$ a word. Say we have the following language:
$ L’ = \{ aw  w \in L \} \cup \{ bw  w \notin L \}$
That is, $ L’$ consists of the words that are in $ L$ with an $ a$ added at the beginning and the words that are not in $ L$ with a $ b$ at the beginning.
Is $ L’$ not recursive? If we have the Turing Machine $ TM$ that decides $ L’$ , $ TM$ will halt for some positive cases ($ w \in L$ ) but for other positive cases ($ w \notin L$ ) it won’t halt. Is it therefore not recursive and recursively enumerable?
From what I understand:

Recursively enumerable: the Turing Machine will always halt if $ w \in L$ , otherwise it may or not halt.

Recursive: it always halts.

Recursively enumerable, but not recursive: it only halts if $ w \in L$ ; otherwise it loops.

Not recursively enumerable: no Turing Machine exists.
So I don’t know how to classify a language whose Turing Machine halts for some of its words.
what are the Edge cases for the following TCP server in android would failed?
I have created a TCP server thread which I want to keep running and Kept on Listening to the IOT device ie RFID reader. as I have only one client. Please review my code and Provide your assistance
public class TcpServerThread extends Thread { private static final String TAG = "TcpServerThread"; private boolean run_ = true; DataInputStream stream; ServerSocket serverSocket; Socket clientSocket; public TcpServerThread() { super(); start(); //start the thread } @Override public void run() { Long loop_count = Long.valueOf(0); byte[] inBytes = new byte[200]; int a = 1025; String IP = MiscUtilities.getIpAccess(); Log.d(TAG, "IP " + IP); //creating a socket to listen on a given port Log.d(TAG, "PORT OPENED SUCESSFULLY in " + a); try { serverSocket = new ServerSocket(a); } catch (IOException e) { Log.d(TAG, "run: [exception occured in creating the socket]" + e.getLocalizedMessage()); } int input = 0; while (run_) { Log.d(TAG, "run() :started"); loop_count++; try { while (serverSocket != null) { Log.d(TAG, "run() : running "); try { //accepting the incoming socket connection request long started = System.currentTimeMillis(); clientSocket = serverSocket.accept(); clientSocket.setKeepAlive(true); if (clientSocket != null) { long established = (System.currentTimeMillis()  started); Log.d(TAG, "[Connection made at]:" + clientSocket.getRemoteSocketAddress() + "in mills :" + established); DataInputStream stream = new DataInputStream(clientSocket.getInputStream()); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); while ((input = stream.read(inBytes)) != 1) { Log.d(TAG, "Size read is " + input); Log.d(TAG, "Data is " + MiscUtilities.bytesToHex(inBytes)); outToServer.writeByte(10); } } } catch (IOException e) { Log.d(TAG, "IOexception occured: " + e.getLocalizedMessage()); continue; } catch (Exception e) { Log.d(TAG, "EXCEPTION occured: " + e.getLocalizedMessage()); continue; } } } catch (Exception e) { //we need to watch out for IllegalStateException cases Log.d(TAG, "[Exception occured] :" + e.getLocalizedMessage()); MiscUtilities.handleSilentException(e); continue; } } try { throw new RuntimeException(TAG + " Crashed!!"); } catch (RuntimeException e) { MiscUtilities.handleSilentException(e); } } public void abort() { run_ = false; closeServer(); interrupt(); } public void closeServer() { try { serverSocket.close(); clientSocket.close(); stream.close(); } catch (Exception e) { Log.d(TAG, "closeServer: " + e.getLocalizedMessage()); } finally { start(); } }
can anyone review my code and provide feedback please
Getting error while accessing the room database in instrumentation test cases – Android
I am using room database in my app. I have Login feature in my app, where after taking userId & password, on click of Login button
I am calling API and storing the response data in room database table after getting a successful callback response from API.
Now I want to write integration test cases for database data, where I am using mockWebServer to mock the API response and storing that in the room database table.
And later I am fetching the DB values & testing whether those are stored properly or not but I am getting below error
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
On this line authentication = authenticationDao.getAuthInformation();
Below is my test cases code:
@RunWith(AndroidJUnit4.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestLogin { @Rule public InstantTaskExecutorRule mInstantTaskExecutorRule = new InstantTaskExecutorRule(); @Rule public ActivityTestRule<LoginActivity> activityTestRule = new ActivityTestRule<>(LoginActivity.class, true, false); @Rule public MockWebServerTestRule mockWebServerTestRule = new MockWebServerTestRule(); @Mock Application application; LoginViewModel loginViewModel; AppDatabase appDatabase; AuthenticationDao authenticationDao; Authentication authentication; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); loginViewModel = new LoginViewModel(application); ApiUrls.TOKEN = mockWebServerTestRule.mockWebServer.url("/").toString(); appDatabase = Room.inMemoryDatabaseBuilder(InstrumentationRegistry.getContext(), AppDatabase.class).build(); authenticationDao = appDatabase.authenticationDao(); activityTestRule = new ActivityTestRule<>(LoginActivity.class, true, true); String fileName = "valid_login_response.json"; mockWebServerTestRule.mockWebServer.enqueue(new MockResponse() .setBody(RestServiceTestHelper.getStringFromFile(getContext(), fileName)) .setResponseCode(HttpURLConnection.HTTP_OK)); Intent intent = new Intent(); activityTestRule.launchActivity(intent); loginViewModel.userName.postValue("Elon"); loginViewModel.password.postValue("Musk123"); loginViewModel.getAuthenticateTokenData(); mockWebServerTestRule.mockWebServer.takeRequest(); } @Test public void a_testDbEntryOnValidResponse() { authentication = authenticationDao.getAuthInformation(); String issueTime = authentication.getIssueDateTime(); String expirationTime = authentication.getExpireDateTime(); String refreshToken = authentication.getRefreshToken(); Assert.assertEquals("Tue, 16 Apr 2019 10:39:20 GMT", issueTime); Assert.assertEquals("Tue, 16 Apr 2019 10:54:20 GMT", expirationTime); Assert.assertEquals("e2b4dfd7205587745aa3100af9a0b", refreshToken); } }
Below is my AppDatabase
class:
@Database(entities = {Authentication.class, UserProfile.class}, version = 1, exportSchema = false) public abstract class AppDatabase extends RoomDatabase { private static AppDatabase INSTANCE; public static AppDatabase getAppDatabase(Context context) { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context, AppDatabase.class, "myappdatabase") .allowMainThreadQueries() .build(); } return INSTANCE; } public abstract AuthenticationDao authenticationDao(); public abstract UserProfileDao userProfileDao(); }
What could be the issue? Is my test case right? Thank you in advance.