Should unit test expected results be hardcoded?

Should the expected results of a unit test be hardcoded, or can they be dependant on initialised variables? Do hardcoded or calculated results increase the risk of introducing errors in the unit test? Are there other factors I haven’t considered?

For instance, which of these two is a more reliable format?

[TestMethod] public void GetPath_Hardcoded() {     MyClass target = new MyClass("fields", "that later", "determine", "a folder");     string expected = "C:\Output Folder\fields\that later\determine\a folder";     string actual = target.GetPath();     Assert.AreEqual(expected, actual,         "GetPath should return a full directory path based on its fields."); }  [TestMethod] public void GetPath_Softcoded() {     MyClass target = new MyClass("fields", "that later", "determine", "a folder");     string expected = "C:\Output Folder\" + string.Join("\", target.Field1, target.Field2, target.Field3, target.Field4);     string actual = target.GetPath();     Assert.AreEqual(expected, actual,         "GetPath should return a full directory path based on its fields."); } 

EDIT 1: In response to DXM’s answer, is option 3 a preferred solution?

[TestMethod] public void GetPath_Option3() {     string field1 = "fields";     string field2 = "that later";     string field3 = "determine";     string field4 = "a folder";     MyClass target = new MyClass(field1, field2, field3, field4);     string expected = "C:\Output Folder\" + string.Join("\", field1, field2, field3, field4);     string actual = target.GetPath();     Assert.AreEqual(expected, actual,         "GetPath should return a full directory path based on its fields."); } 

Import “Stop on Error” does not work as expected

The “Stop on Error” feature in System > Data Transfer > Import does not work as expected. It only seems to work when checking for required columns. But when there are validation errors (like “please make sure attribute group_id is not empty”), it processes each of the rows (in my case thousands) and outputs a list of all rows with errors.

I have the defaults set to “Stop on Error”, “Allowed Errors Count: 10”.

Is “Stop on Error” only designed for one type of error (column existence)?

Row swapping not working as expected for determinant

Suppose I have determinant A such that $ $ A= \begin {vmatrix} 1&0&1 \ 5&-1&0 \ 1&0&0 \end {vmatrix} $ $

I conduct row operation $ R_1 <-> R_3 $ So I should have $ $ A = – \begin {vmatrix} 1&0&0 \ 5&-1&0 \ 1&0&1 \end {vmatrix} $ $

but that does not seem to be the case because in the first case A=-1 and in the other A=1
That isn’t working as expected. What am I missing here?

Error when parsing my .bashrc — sytax error: operand expected (error token is ” “)

I have the following snippet in my .bashrc:

# Returns system load as percentage, i.e., '40' rather than '0.40)'. function load() {     local SYSLOAD=$  (cut -d " " -f1 /proc/loadavg | tr -d '.')     # System load of the current host.     echo $  ((10#$  SYSLOAD))       # Convert to decimal. } 

When it’s parsed, I get this error: bash: 100* : syntax error: operand expected (error token is " ") but I’m not sure why?

ARP spoofing doesn’t work as expected?

I have seen products like CUJO ( and Firewalla ( doing ARP spoofing for network filtering and device blocking.

As far as know, simplest way to reproduce same situation is to use arpspoof. I have tested this, and it works only partically. I mean it does indeed redirect traffic from victim (test Macbook) to gateway (Asus router) and vice versa. Pings are working fine between both. But upon entering any website from the internet, it is loading so slowly that it is impossible to work with it. arpspoof sends 2 gratuitous ARP packets (1 for victim, one for gateway) each 2 seconds.

I was wondering how does CUJO and Firewalla work with unvisible performance drop, if home-made tests using arpspoof are not working as expected?

(Yes I have packet forwarding enabled within /proc/sys/net/ipv4/ip_forward)


  • Victim = Macbook Air ( (connected via WiFi)
  • Attacker = HP notepad with Debian 9 ( on Gigabit port
  • Router (Asus) = (

I have tested my Android phone aswell with WiFi, and same thing, internet pages are opening very slowly if not at all.

What is the expected value from these two different coin tossing games?

Consider these two games:

Game 1: Toss 4 coins. If coins 1 and 2 are heads, you win $ $ $ 5. If coins 3 and 4 are heads, you win an additional $ $ $ 5.

Game 2: Toss 3 coins. If coins 1 and 2 are heads, you win $ $ $ 5. If coins 2 and 3 are heads, you win an additional $ $ $ 5.

My question is, which game will have the highest expected value for winnings? The case of game 1 is simple. Receiving $ $ $ 5 from tossing coins 1 and 2 and receiving $ $ $ 5 from tossing coins 3 and 4 are independent events. Therefore, if the coins lands heads with probability $ p$ , the expected value of the winnings is$ $ E(Game \; 1) = 5 p^2 + 5 p^2 = 10p^2. $ $ In game 2, we still have the probability $ p^2$ of winning the first $ $ $ 5. However, the probability of receiving the additional $ $ $ 5 from coin 3 is dependent upon having a heads in coin 2. I figured so far that $ $ E(Game\;2) = 5p^2 + x$ $ I am not sure what $ x$ is. Which result links the expected value of an event when conditional probabilities are involved?

Expected Value Iteratively picking divisors of number

You have a positive integer $ n$ written on a blackboard, and you perform $ k$ iterations of the following procedure: say the current number is $ v$ . Pick one of the divisors of $ v$ (possibly 1 and $ v$ itself) and replace $ v$ with this divisor. Each divisor is equally likely to be chosen.

What is the expected value of the number on the blackboard after $ k$ iterations?

[This questions is taken from Hello2019D Codeforces]

The expected value of Beta Function

Estimate the probability of success

Suppose I send 10 tasks to my machine. 6 out of 10 tasks success, and 4 failed. These outcomes is summarized by $ X$ as a binary variable, 1 is task success, and 0 if task fail. We know that $ X$ is continuous random variable

The expected value of a continuous random variable is dependent on the probability density function used to model the probability that the variable will have a certain value. Therefor, I exploit Beta distribution to estimate the probability of success for next tasks. I will $ {\alpha}$ as input of the number past success tasks and $ {\beta}$ as the number of past fail tasks

Expected value

\begin{equation} E(x) = \frac{\alpha+1}{\alpha+\beta+2} \end{equation}

In my example, $ \alpha = 6$ and $ \beta = 4$ . Thus, the $ E(x)$ = 0.58.

Does every think looks good?

Windows file permissions – Admin permissions don’t seem to work as expected / access denied

I have just inherited a server and I have an issue accessing some folders. I usually get this solved “in the end”, usually by forcing a takeown command and then starting from scratch – but, it’s annoying me and I would really like to understand why this going on.

I created a new user for myself with all the standard admin groups:

enter image description here

If I go to the drive holding everyone’s profiles, I can see that the folders all have:

  1. The user with full access
  2. 3 different admin users with full access
  3. The administrator group with full access (which I am a member of).

When I click on the folder, despite being a member of the admin group, I am presented with:

enter image description here

If I do continue, and then look back at the folder’s permissions, it has added me as an individual.

Taking the above in to consideration, my questions are:

  1. Why does it add me as a user and not just let me in through the group I am a member of after clicking continue (above)?

  2. At random, I get errors accessing folders within the folder – If I try to go to advanced security and add myself, then I do the “replace all child object permissions”, why does it randomly give me access denied on some child items?

  3. Why is it that even if I try to force taking ownership, I also get access denied (as an administrator)?

In the end, as I said above, I usually just end up doing a recursive takeown, but, I just feel like I am missing something here – I don’t get why something seemingly simple gets complicated.

enter image description here