Update it all, VisualStudio Changes

This commit is contained in:
2016-08-23 12:33:06 -05:00
parent 2a0c6f9e45
commit b8814259b5
136 changed files with 180080 additions and 66 deletions

40
csharp/anagram/Anagram.cs Normal file
View File

@@ -0,0 +1,40 @@
using System.Collections.Generic;
internal class Anagram {
private string v;
// Anagram is initialized with a string to test other strings against
public Anagram(string v) {
this.v = v.ToLower();
}
// Match takes an array of strings and returns an array that contains
// All anagrams of this.v
public string[] Match(string[] inp) {
List<string> ret = new List<string>();
foreach(string val in inp) {
if(this.v.Length != val.Length) {
continue;
}
string valTest = val.ToLower();
bool isAnagram = true;
if(this.v == valTest) {
continue;
}
for(int i = 0; i < this.v.Length; i++) {
int idx = valTest.IndexOf(this.v[i]);
if(idx == -1) {
isAnagram = false;
}
if(!isAnagram) {
break;
}
valTest = valTest.Substring(0, idx)+valTest.Substring(idx+1);
}
if(isAnagram) {
ret.Add(val);
}
}
return ret.ToArray();
}
}

View File

@@ -0,0 +1,96 @@
using NUnit.Framework;
[TestFixture]
public class AnagramTest
{
[Ignore]
[Test]
public void No_matches()
{
var detector = new Anagram("diaper");
var words = new[] { "hello", "world", "zombies", "pants" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_simple_anagram()
{
var detector = new Anagram("ant");
var words = new[] { "tan", "stand", "at" };
var results = new[] { "tan" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_multiple_anagrams()
{
var detector = new Anagram("master");
var words = new[] { "stream", "pigeon", "maters" };
var results = new[] { "maters", "stream" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Does_not_confuse_different_duplicates()
{
var detector = new Anagram("galea");
var words = new[] { "eagle" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Identical_word_is_not_anagram()
{
var detector = new Anagram("corn");
var words = new[] { "corn", "dark", "Corn", "rank", "CORN", "cron", "park" };
var results = new[] { "cron" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Eliminate_anagrams_with_same_checksum()
{
var detector = new Anagram("mass");
var words = new[] { "last" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Eliminate_anagram_subsets()
{
var detector = new Anagram("good");
var words = new[] { "dog", "goody" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_anagrams()
{
var detector = new Anagram("allergy");
var words = new[] { "gallery", "ballerina", "regally", "clergy", "largely", "leading" };
var results = new[] { "gallery", "largely", "regally" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Anagrams_are_case_insensitive()
{
var detector = new Anagram("Orchestra");
var words = new[] { "cashregister", "Carthorse", "radishes" };
var results = new[] { "Carthorse" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
}

21
csharp/anagram/README.md Normal file
View File

@@ -0,0 +1,21 @@
# Anagram
Write a program that, given a word and a list of possible anagrams, selects the correct sublist.
Given `"listen"` and a list of candidates like `"enlists" "google"
"inlets" "banana"` the program should return a list containing
`"inlets"`.
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file you're submitting is in the `exercism/csharp/<exerciseName>` directory.
For example, if you're submitting `bob.cs` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/csharp/bob/bob.cs`.
## Source
Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.