Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ar7z1 committed Jul 13, 2017
1 parent 14b6efd commit c507a51
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Write(DecisionTree tree, string className)
writer.WriteLine("namespace DecisionTrees");
writer.WriteLine("{");
writer.WriteLine(" using System.CodeDom.Compiler;");
writer.WriteLine(" using System.Collections.Generic;");
writer.WriteLine(" using System;");
writer.WriteLine();
writer.WriteLine(" /// <summary>");
writer.WriteLine(" /// Automatically generated decision tree.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="..\..\Samples\MachineLearning\Liblinear %28SVMs%29\Train.cs">
<Link>VectorMachines\Liblinear\Train.cs</Link>
</Compile>
<Compile Include="DecisionTrees\DecisionTreeWriterTest.cs" />
<Compile Include="POSTest.cs" />
<Compile Include="TFIDFTest.cs" />
<Compile Include="BagOfWordsTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.CodeDom.Compiler;
using System.Text;
using Accord.MachineLearning.DecisionTrees;
using Microsoft.CSharp;
using NUnit.Framework;

namespace Accord.Tests.MachineLearning
{
[TestFixture]
public class DecisionTreeWriterTest
{
[Test]
public void WriteTest()
{
DecisionTree tree;
int[][] inputs;
int[] outputs;
ID3LearningTest.CreateMitchellExample(out tree, out inputs, out outputs);

var csc = new CSharpCodeProvider();
var parameters = new CompilerParameters(new[] { "System.dll", "mscorlib.dll" }) {GenerateInMemory = true};

var compilerResult = csc.CompileAssemblyFromSource(parameters, tree.ToCode("AccordDecisionTree"));

Assert.That(compilerResult.Errors.HasErrors, Is.False, ToString(compilerResult.Errors));
}

private static string ToString(CompilerErrorCollection compilerErrors)
{
var builder = new StringBuilder("Compiler errors:\n");
foreach (var error in compilerErrors)
builder.AppendLine(error.ToString());
return builder.ToString();
}
}
}

0 comments on commit c507a51

Please sign in to comment.