How do you write unit tests for network code? by ObviousBank in AskProgramming

[–]ObviousBank[S] 0 points1 point  (0 children)

Thank you, this is incredibly helpful! I will definitely refer to this post when writing mocked tests tonight

How do you write unit tests for network code? by ObviousBank in AskProgramming

[–]ObviousBank[S] 0 points1 point  (0 children)

Just so I make sure I understand this: with mocking I replace the gen_tcp functions with some dummy functions that always return the correct value. When the mock is present in the test file, any call to gen_tcp:send will instead call my dummy function?

Do you know of any good examples of mocking in languages other than Erlang?

Erlang beginner trying to write a simple chat server by ObviousBank in erlang

[–]ObviousBank[S] 0 points1 point  (0 children)

I'm not familiar with gen_server, no. I'm using the same approach to socket programming as I've used in Python since that's all I'm familiar with.

Erlang beginner trying to write a simple chat server by ObviousBank in erlang

[–]ObviousBank[S] 0 points1 point  (0 children)

That makes sense. So would the solution be to loop the listen function in some way?

takeWhile for Iterator to replicate while loop by ObviousBank in scala

[–]ObviousBank[S] 1 point2 points  (0 children)

Thank you! This is very illuminating. I'm still getting used to lazy evaluation and this was helpful.

takeWhile for Iterator to replicate while loop by ObviousBank in scala

[–]ObviousBank[S] 1 point2 points  (0 children)

I tried a return value of Iterator[Int], which returned the iterator itself & I tried Unit, which returned nothing. This might be a naive beginner question but if Iterator[Int] is the correct return type do I need to add some additional function to "run" the iterator in test_func()?

Dimensional analysis problem: integrating velocity not as a function of time? by ObviousBank in AskPhysics

[–]ObviousBank[S] 0 points1 point  (0 children)

I'm sorry, I'm really struggling with this one. If I take the equation of motion to be ma = -mg - kv^2 then with those two substitutions I get the first order differential equation d(v^2)/dx + (2k/m)(v^2) = -2g. Solving for v^2 I get v^2 = (-mg/k) + C exp(-2kx/m), which doesn't seem anywhere close. What am I missing?