Skip to content

Commit b9b6a8b

Browse files
committed
finish 96 percent coverage.
1 parent aebb391 commit b9b6a8b

File tree

7 files changed

+113
-32
lines changed

7 files changed

+113
-32
lines changed

AlphaApplication/Control/AlphaController.cs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,17 @@ public AlphaController()
2222

2323
public List<string> Search(string[] strings)
2424
{
25-
var newStrings = CreateAlphaEngine(strings).ToList();
25+
/*
26+
var newStrings = InitAlphaEngine(strings).ToList();
2627
foreach (var newString in newStrings)
2728
{
2829
AddWord(newString.Trim());
2930
}
30-
31-
int x = 6;
32-
// CreateAlphaEngine(strings).ToList().ForEach(word => AddWord(word));
31+
*/
32+
InitAlphaEngine(strings).ToList().ForEach(word => AddWord(word.Trim()));
3333
return _alphaEngine.ExecuteQuery();
3434
}
3535

36-
private string[] CreateAlphaEngine(string[] strings)
37-
{
38-
AlphaEngineBuilder alphaEngineBuilder = new AlphaEngineBuilder();
39-
if (strings[^1].Equals(" #all"))
40-
{
41-
alphaEngineBuilder.SetPrettyQuery();
42-
strings = strings.Take(strings.Length - 1).ToArray();
43-
}
44-
else
45-
alphaEngineBuilder.SetPrettyQuery(ExecuteQueryBoard);
46-
47-
_alphaEngine = alphaEngineBuilder.Create(_map);
48-
return strings;
49-
}
50-
5136
private void AddWord(string word)
5237
{
5338
char starter = word[0];
@@ -63,5 +48,40 @@ private void AddWord(string word)
6348
break;
6449
}
6550
}
51+
52+
public string ViewDoc(string[] strings)
53+
{
54+
var isComplete = (strings.Length == 2);
55+
var docId = InitAlphaEngine(strings)[0];
56+
try
57+
{
58+
if (isComplete)
59+
{
60+
var docContext = _alphaEngine.GetDocByID(docId);
61+
return "Doc <"+ docId + ">: " +"\n" + docContext;
62+
}
63+
return _alphaEngine.GetDocByID(docId);
64+
}
65+
catch (DocumentNotFoundException e)
66+
{
67+
return "!Document Not Found!\n";
68+
}
69+
}
70+
71+
private string[] InitAlphaEngine(string[] strings)
72+
{
73+
AlphaEngineBuilder alphaEngineBuilder = new AlphaEngineBuilder();
74+
if (strings[^1].Equals(" #all"))
75+
{
76+
alphaEngineBuilder.SetPrettyQuery();
77+
strings = strings.Take(strings.Length - 1).ToArray();
78+
}
79+
else
80+
{
81+
alphaEngineBuilder.SetPrettyQuery(ExecuteQueryBoard).SetSummarizedDoc();
82+
}
83+
_alphaEngine = alphaEngineBuilder.Create(_map);
84+
return strings;
85+
}
6686
}
6787
}

AlphaApplication/View/Application/AlphaApp.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Text;
56
using AlphaApplication.Control;
67
using AlphaInvertedSearcher.Engine;
78

@@ -36,11 +37,12 @@ public AlphaApp() :
3637
protected override void InitExecutors()
3738
{
3839
Executors.Add("^search( \\S+)+$", args => Search(args));
40+
Executors.Add("^view doc (\\S+){1,20}$", args => ViewDoc(args));
41+
Executors.Add("^view doc (\\S+){1,20}( #all)$", args => ViewDoc(args));
3942
Executors.Add("^show help$", args => ShowHelp());
4043
Executors.Add("^exit$", args => Exit());
4144
}
4245

43-
4446
private void ShowHelp()
4547
{
4648
PrintWithDesign(AlphaDesign.AlphaHelp.Item1, true, DefaultBackGroundColor, AlphaDesign.AlphaHelp.Item2);
@@ -60,5 +62,26 @@ private void Search(String[] strings)
6062
Console.WriteLine();
6163
}
6264

65+
private void ViewDoc(string[] args)
66+
{
67+
var result = _alphaController.ViewDoc(args);
68+
var splits = result.Split("\n");
69+
PrintWithDesign(splits[0], true, DefaultBackGroundColor, HeaderColor);
70+
var builder = new StringBuilder();
71+
for (int i = 1; i < splits.Length; i++)
72+
{
73+
builder.Append(splits[i] + "\n");
74+
}
75+
76+
if (!builder.ToString().Equals("\n"))
77+
{
78+
PrintWithDesign(builder.ToString(), true, DefaultBackGroundColor, ContextColor);
79+
}
80+
else
81+
{
82+
Console.WriteLine();
83+
}
84+
}
85+
6386
}
6487
}

AlphaApplication/View/Application/Executable.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ protected void ExecuteCommand(string command)
3131

3232
private static string[] GetParameters(GroupCollection groupCollection)
3333
{
34-
return groupCollection[1]
35-
.Captures
36-
.ToList()
37-
.Select(capture => capture.ToString())
38-
.ToArray();
34+
var parameters = new List<string>();
35+
for (int i = 1; i < groupCollection.Count; i++)
36+
{
37+
parameters.AddRange(groupCollection[i].Captures.ToList().Select(capture => capture.ToString()).ToList());
38+
}
39+
40+
return parameters.ToArray();
3941
}
4042
}
4143

AlphaApplicationTest/AlphaApplicationTest.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,4 @@
1717
<ProjectReference Include="..\AlphaApplication\AlphaApplication.csproj" />
1818
</ItemGroup>
1919

20-
<ItemGroup>
21-
<Folder Include="ViewTest\Utils" />
22-
</ItemGroup>
23-
2420
</Project>

AlphaApplicationTest/ViewTest/AlphaAppTest.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,45 @@ public void SearchAllQueryTest()
6969
"AlphaTeam Appreciates Your Usage. GoodBye \n\n";
7070
Assert.Equal(expected, output);
7171
}
72+
73+
[Fact]
74+
public void ViewDocTest() {
75+
var output = getOutputFromInput("view doc 57110\nexit\n");
76+
var expected = "Hello, This Is " + "Alpha-Avg" + "." +
77+
"\n*-Enter <show help> to see the guidance-*" + "\n\n" +
78+
"Alpha-Avg> " +
79+
"Doc <57110> Summary: \n" +
80+
"I have a 42 yr old male friend, misdiagnosed as havin osteopporosis for two years,...\n\n" +
81+
"Alpha-Avg> " +
82+
"AlphaTeam Appreciates Your Usage. GoodBye \n\n";
83+
Assert.Equal(expected, output);
84+
}
85+
86+
[Fact]
87+
public void ViewAllDocTest()
88+
{
89+
var output = getOutputFromInput("view doc 57110 #all\nexit\n");
90+
var expected = "Hello, This Is " + "Alpha-Avg" + "." +
91+
"\n*-Enter <show help> to see the guidance-*" + "\n\n" +
92+
"Alpha-Avg> " +
93+
"Doc <57110>: \n" +
94+
"I have a 42 yr old male friend, misdiagnosed as havin osteopporosis for two years, who recently found out that hi illness is the rare Gaucher's disease.Gaucher's disease symptoms include: brittle bones (he lost 9 inches off his hieght); enlarged liver and spleen; interna bleeding; and fatigue (all the time). The problem (in Type 1) i attributed to a genetic mutation where there is a lack of th enzyme glucocerebroside in macrophages so the cells swell up This will eventually cause deathEnyzme replacement therapy has been successfully developed an approved by the FDA in the last few years so that those patient administered with this drug (called Ceredase) report a remarkabl improvement in their condition. Ceredase, which is manufacture by biotech biggy company--Genzyme--costs the patient $380,00 per year. Gaucher\\'s disease has justifyably been called \"the mos expensive disease in the world\"NEED INFOI have researched Gaucher's disease at the library but am relyin on netlanders to provide me with any additional information**news, stories, report**people you know with this diseas**ideas, articles about Genzyme Corp, how to get a hold o enough money to buy some, programs available to help wit costs**Basically ANY HELP YOU CAN OFFEThanks so very muchDeborah\n\n" +
95+
"Alpha-Avg> " +
96+
"AlphaTeam Appreciates Your Usage. GoodBye \n\n";
97+
Assert.Equal(expected, output);
98+
}
99+
100+
[Fact]
101+
public void ViewDocNotFoundTest() {
102+
var output = getOutputFromInput("view doc abc #all\nexit\n");
103+
var expected = "Hello, This Is " + "Alpha-Avg" + "." +
104+
"\n*-Enter <show help> to see the guidance-*" + "\n\n" +
105+
"Alpha-Avg> " +
106+
"!Document Not Found!\n\r\n" +
107+
"Alpha-Avg> " +
108+
"AlphaTeam Appreciates Your Usage. GoodBye \n\n";
109+
Assert.Equal(expected, output);
110+
}
72111
}
112+
73113
}

AlphaInvertedSearcher/Engine/Engine/Decorator/AlphaEngineDocDecorator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override string GetDocByID(string docID)
2626
}
2727

2828
private string PrintModifiedWords(string header, string context) {
29-
string answer = header + " Summery: \n";
29+
string answer = "Doc <"+ header + "> Summary: \n";
3030
int board = this.board;
3131
for (int i = 0; i < context.ToCharArray().Length; i++) {
3232
if(context[i] == ' ') {

AlphaInvertedSearcherTest/EngineTest/DecoratorTest/DecorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void EngineBuilderTest2()
2323
{
2424
var alphaEngine = _engineBuilder.SetSummarizedDoc(2).Create(MapTest.InitMapper());
2525
Assert.NotEqual("The Witcher is a role-playing", alphaEngine.GetDocByID("1.txt"));
26-
Assert.Equal("1.txt Summery: \nThe Witcher...", alphaEngine.GetDocByID("1.txt"));
26+
Assert.Equal("Doc <1.txt> Summary: \nThe Witcher...", alphaEngine.GetDocByID("1.txt"));
2727
var resultSet = alphaEngine.AddMustIncludes("Witcher").AddMustIncludes("WiTchEr", "is").AddLeastIncludes("AnyA")
2828
.AddExcludes("role-playing").ExecuteQuery();
2929
Assert.Equal(new List<string>(), resultSet);
@@ -45,7 +45,7 @@ public void EngineBuilderTest3()
4545
public void EngineBuilderTest4()
4646
{
4747
var alphaEngine = _engineBuilder.SetPrettyQuery(1).SetSummarizedDoc(2).Create(MapTest.InitMapper());
48-
Assert.Equal("1.txt Summery: \nThe Witcher...", alphaEngine.GetDocByID("1.txt"));
48+
Assert.Equal("Doc <1.txt> Summary: \nThe Witcher...", alphaEngine.GetDocByID("1.txt"));
4949
var resultSet = alphaEngine.AddLeastIncludes("WitCHER", "aNyA").ExecuteQuery();
5050
Assert.Equal(new List<string>()
5151
{

0 commit comments

Comments
 (0)