Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In one of the interview I was asked to test a method. The details are mentioned below. Though I could answer , still they were expecting some more test cases. Am I missing any scenarios here ?
string concatenatefunc(strin1,string2).
{
//returns concatenation
}
This method accepts two string parameters and returns the concatenation. No other details are mentioned. I need to test this method and i have written below scenarios/unit test cases:
1.Pass empty parameters and see empty string is returned
2.Pass valid non empty strings and see the string returned is correct or not.
3.Pass the special characters in the both the parameters and test the response.
4.Pass integers and test the response.
5.pass large strings(not sure what we can give as the max length) and test the response.
....
Anything to add here?
You're not testing for null parameters.
Test for multi language support. An area that many developers fail to test which can give a guy like me problems. I have the danish character 'ø' in my name. This has been a problem in my web based interactions with several VERY BIG companies including software companies, preventing me from logins, accounts, payments etc.
Number 5 will really depend on the size of available resources so testing that might be problematic.
You could add tests for either parameter being empty and see if the non-empty parameter is returned
Same for Passing integers, test if either parameter is integer
Then you could start mixing them empty/integer, non-empty/integer, etc. and reverse
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Given the Following code:
List<Digit> tempDigits = input.Digits;
string test = tempDigits.ToString(); // -> {2,2,7}
tempDigits.Reverse();
string test2 = tempDigits.ToString(); // -> {2,2,7}
This is my code:
and that the result (in between, I renamed the variable according to naming convention as suggested by Thiessen)
For some reason, the reverse soes not seem to do its job.
It must be something really simple. But I cant get what the Issue is. I hope, someone can help out.
The code you've posted would work correctly, in a vacuum. (Except, in what world does List<>.ToString() produce "{2,2,7}"?)
My main guess would be, as Lesiak commented, that this.Digits and input.Digits points to the exact same List<> instance. So Digits1.Reverse() reverses the list and Digits2.Reverse() reverses the reversal, putting it back how it started. Perhaps this and input are the same thing. Or perhaps they are two different things that happen to use the same underlying Digits list. Who knows?
There are many other possibilities, some of which would be impossible to guess at based on the information provided. For example:
Maybe the input control that's giving you that list is trying to actively manage the list, and reorders it as soon as it notices it's been reversed.
Maybe you're not using the System.Collections.Generic.List<> type, but instead you're referencing some other namespace where someone has written a List<> type that doesn't behave how you'd think it would. Maybe it doesn't even implement Reverse(), so the compiler is picking up on the Enumerable.Reverse() extension method, which does nothing to mutate the underlying data.
It really is impossible to know for sure without knowing more about your environment.
The information you give is incomplete to address the issue.
A reproducible example from the information you provide does not show the same symptoms.
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<int> digits = new List<int> {2,2,7};
foreach(int digit in digits)
Console.Write(digit);
Console.WriteLine();
digits.Reverse();
foreach(int digit in digits)
Console.Write(digit);
Console.WriteLine();
}
}
Which gives the expected output
227
722
https://dotnetfiddle.net/Hs9H0k
My guess would be, this.Digits is not a mutable reference. But that is just an hypothesis.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am very sure that there is a technical term for this problem, but unfortunately I do not know it.
I have an alphabetical charset and the requirement is to create the combination of all the chars with a maximum length
The idea is (sample):
Generate a collection of A, AA, AAA, AAAA, AAAAA, AAAAAA
Next: A, AB, ABA, ABAA, ABAAA
Next A, AB, ABB, ABBA, ABBAA
The reason:
We have to query an API that delivers search results.
But if I don't get search hits from the API on AAA, I don't need to search for AAAA anymore, because it can't get search hits either. I can then move on to AAB.
The question:
My problem is that I'm not sure how the code has to be built to achieve this goal. I lack the structural approach.
I've already tried nested loops, but unfortunately I don't get the result.
I also used Combination Libraries, but they focus on other problems.
Many thanks for hints!
What you're looking for is a particular data structure called a Tree, but probably more specifically in your case, a Trie.
Trie data structures are commonly used in things like Autocomplete. With the image below, if someone typed "te", I can traverse the Trie and see what options would come after that (tea, ted, ten).
It looks like this would also fit your use case from what I can tell.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
The static Matches is
public static void Matches(string expectedRegexPattern, string actualString);
What is the difference between when I pass expectedRegexPattern value instead of actualString value and passing actualString value instead of expectedRegexPattern value?
Way 1 - Assert.Matches("EN", result[0].LanguageCode);
Way 2 - Assert.Matches(result[0].LanguageCode,"EN");
Both of ways doing same work with same performance. So am confused about the difference between the above ways and which one is best?
#Stivi correctly points out a significant difference in the case of Matches, but there's another less significant but still important distinction even for Equals and other assertion methods.
You might get an incorrect message in the test log output. Many testing frameworks will log an error such as
Values do not match: expected: {expectedValue}, actual: {actualValue}".
So if you switched them, you'd see the wrong "expected" value, potentially confusing someone trying to diagnose a problem.
Take this test as an example:
void TestValueIsZero():
{
int value = 1;
Assert.Equals(0, value);
// logs "Values to not match. expected: 0, actual: 1
Assert.Equals(value, 0);
// logs "Values to not match. expected: 1, actual: 0
}
Someone looking at the failed test logs might be confused by the incorrect "expected" and "actual" values in the log due to the switched parameters.
The mechanics may be exactly the same regardless of the order of parameters (compare the two objects and return true if no differences are found), but the semantics are still important.
I expect that you are using xunit as test framework because i have found that method there. So if you only want to check if both strings have the same content you could also use Assert.Equal("Your text", "Your text"). The Assert.Matches method is used to validate if your text is in a desired format. The format is described by .net regular expressions. For example with this call Assert.Matches("^[0-9]$", "1") you can check if your string is a number between 0 and 9. If you change the order of the parameters to Assert.Matches( "1", "^[0-9]$") the method will throw an exception and your test will be marked as failed.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hello experts, I have to generate series of folders from a TextBox into specified location.I am having two textboxes to specify the limit of folders(say 30 folders).The problem am facing is that the folder names that i will be providing are alpha-numeric(say 121cs3h101) .
How to set limit when i provide an alpha-numeric values?
(For example: i provide textbox1=12cs3h101 and textbox2=12cs3h131 , i need the series limit to be generated). I am working with visual studio 2013 in c# windows form application. Thanks in advance.
ok I will try to give you a lead.
To parse a string or find specific characters one can use RegEx.Match or a simler method called String.Split. In both cases you have to be aware how your string is structured and how it can vary. The limits of variation are very important.
If as you say the beginning is always"12cs3h" you can either split the string at the character 'h'.
string[] sa = s.Split('h');
Or you can even use the index of 'h' (since the length seems to be fixed) and take the rest of the string to get the numbers.
int index = s.IndexOf('h');
The rest is up to you, ... convert, enumerate and so on.
EDIT: There is a nice method that does the enumeration job for you: Enumerable.Range Good luck
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I hope it's OK to ask this question here.
I was asked a question at the interview - with a description in the title.
For example, for given string "ABABDCABDCDDPPABAB" - it would return AB because it appears most times.
Even though I could answer the question - second part of the question was to write a unit test for this method, which would be able to test all possible scenarios!
Could anyone point me on how to tackle such question?
You should answer some questions relates to proposed behavior of the function. For example:
What if source string is null?
What if source string is shorter than two characters?
What if source string contains two or more pairs of characters with the same frequency?
All of you answers you can rewrite as a test methods:
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void FindMostFrequentPair_WithNull_ThrowsArgumentNullException()
{
var pair = Utils.FindMostFrequestPair(null);
}
[TestMethod]
public void FindMostFrequentPair_WithSameFrequentPairs_ReturnsFirst()
{
var pair = Utils.FindMostFrequestPair("ABCD");
Assert.AreEqual("AB", pair);
}
and so on.
Test boundary cases, i.e. null and empty strings, strings with odd number of characters, etc. Also test obvious successful case — you function should work.
The answer would be to test the different possibilities such as:
Testing when AB appears the most
Testing when AB appears the least
Testing when AB appears the same amount as PA
Testing what happens with unexpected input like a null string.
There are probably more options but that would need a look at the code before going into them like verifying certain methods are called etc etc