-3

I am trying to learn C# and I'm still a beginner. recently, I have discovered a website that allows you to practice and train, but I faced a problem while working on it. When I type this code in Visual Studio, it works, but it doesn't on the website and the site tells me that I have an error!

The website is: www.codewars.com

The code is:

public class DnaStrand 
{
    public static string MakeComplement(string dna)
    {
        int length = dna.Length;
        string [] smash = new string[length];
        for (int i = 0; i < length; i++)
        {
            smash[i] = n.Substring(i,1);
        }
        for (int k = 0; k < length; k++)
        {
            if (smash[k] == "A") { smash[k] = "T"; }
            else if (smash[k] == "T") { smash[k] = "A"; }
            else if (smash[k] == "G") { smash[k] = "C"; }
            else if (smash[k] == "C") { smash[k] = "G"; }
        }
        for (int o = 0; o < length; o++)
        {
            Console.Write(smash[o]);
        }
    }
}

The error that the site shows

Edit

The error is:

/home/codewarrior/fixture.cs(1,17): error CS0234: The type or namespace name VisualStudio' does not exist in the namespaceMicrosoft'. Are you missing an assembly reference?

Error: Command failed: mcs -out:/home/codewarrior/test.dll -lib:/home/codewarrior,/runner/frameworks/csharp/mono-4.5,/runner/frameworks/csharp/nunit/bin -langversion:Default -sdk:4.5 -warn:2 -target:library -r:nunit.core.dll,nunit.framework.dll,nunit.core.interfaces.dll,nunit.util,Newtonsoft.Json.dll -r:System.Numerics.dll -r:System.Drawing.dll -r:System.Data.dll -r:System.Data.SQLite.dll -r:System.Data.SQLite.Linq.dll -r:System.IO.dll -r:System.Linq.dll -r:System.Linq.Dynamic.dll -r:System.Linq.Expressions.dll -r:System.Messaging.dll -r:System.Threading.Tasks.dll -r:System.Xml.dll -r:Mono.Linq.Expressions.dll /home/codewarrior/code.cs /home/codewarrior/fixture.cs /home/codewarrior/fixture.cs(1,17): error CS0234: The type or namespace name VisualStudio' does not exist in the namespaceMicrosoft'. Are you missing an assembly reference?

Jimmy
  • 27
  • 6
  • You're having a `using Microsoft.VisualStudio;` , where that namespace VisualStudio cannot be found. Possible solutions: https://stackoverflow.com/questions/7922217/namespace-visualstudio-does-not-exist-in-the-namespace-microsoft-missing-assemb https://stackoverflow.com/questions/20259076/type-or-namespace-name-visualstudio-does-not-exist-in-the-namespace-microsoft – jAC Sep 17 '17 at 13:41
  • It seems the unit tests cannot be compiled because they depend on some assemblies and those assemblies are not available so the site cannot compile your code. – CodingYoshi Sep 17 '17 at 13:42

2 Answers2

2

Basically, the machine that compiles your C# code on CodeWars does not have the Visual Studio unit testing library installed. That explains why it compiles in Visual Studio, because the Visual Studio IDE comes with the testing libraries bundled upon installation, while the CodeWars machine does not, because it seems to be using Mono instead.

According to a CodeWars forum thread, you should use the NUnit framework instead, e.g.:

using NUnit.Framework;

[TestFixture]
public class DnaStrandTest {
    [Test]
    public void test01() {
        Assert.AreEqual("TTTT", DnaStrand.MakeComplement("AAAA"));
    }
    [Test]
    public void test02() {
        Assert.AreEqual("TAACG", DnaStrand.MakeComplement("ATTGC"));
    }
    [Test]
    public void test03() {
        Assert.AreEqual("CATA", DnaStrand.MakeComplement("GTAT"));
    }
}
joaovictortr
  • 319
  • 2
  • 4
1

The problem is CodeWars uses Ubuntu + Mono combo for compilation and you're trying to use MSTest framework which is not a part of the kit.

Based on available libraries I'd use NUnit framework for testing (since it's installed).

orhtej2
  • 2,133
  • 3
  • 16
  • 26