Skip to content

Commit

Permalink
Первый полноценный комплексный подход!
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirpitchnsk committed May 11, 2023
1 parent c0a3a2d commit 11d3cc6
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 23 deletions.
27 changes: 26 additions & 1 deletion LogicSimulator/Models/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using LogicSimulator.Views.Shapes;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -112,6 +111,11 @@ private void Tick() {

(outs2, outs) = (outs, outs2); // Магия здесь!
// Log.Write("Выходы: " + Utils.Obj2json(outs));

if (comparative_test_mode) {
prev_state = cur_state;
cur_state = Export();
}
}

public string Export() => string.Join("", outs.Select(x => x ? '1' : '0'));
Expand All @@ -132,5 +136,26 @@ public void Clear() {
*/

public void TopSecretPublicTickMethod() => Tick();

// Для комплесного решения:

public Switch[] GetSwitches() => items.Select(x => x.item).OfType<Switch>().ToArray();
public LightBulb[] GetLightBulbs() => items.Select(x => x.item).OfType<LightBulb>().ToArray();

// Для УМНОГО комплесного решения XD:

private bool comparative_test_mode = false;
private string prev_state;
private string cur_state;

public bool ComparativeTestMode {
get => comparative_test_mode;
set {
comparative_test_mode = value;
if (value) prev_state = cur_state = Export();
}
}

public bool SomethingHasChanged => prev_state != cur_state;
}
}
2 changes: 2 additions & 0 deletions LogicSimulator/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public void FuncComm(string Comm) {
break;
case "Save":
map.Export();
// Для создания тестовых штучек:
File.WriteAllText("../../../for_test.json", Utils.Obj2json((map.current_scheme ?? throw new System.Exception("Чё?!")).Export()));
break;
case "SaveAs":
map.Export();
Expand Down
4 changes: 2 additions & 2 deletions LogicSimulator/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
<Border Classes="b">
<Grid ColumnDefinitions="*,auto,auto,auto">
<TextBlock Text="{Binding}" Tag="{Binding}"/>
<Button Grid.Column="1" Padding="2" Margin="6 -4 4 -4" Command="{Binding Open}" IsVisible="{Binding CanOpenMe}">
<Button Grid.Column="1" Padding="2" Margin="6 -4 4 -4" Command="{Binding Open}" IsVisible="{Binding CanOpenMe}" Name="OpenScheme">
<Image Width="24" Height="24" Source="/Assets/Open.png"/>
</Button>
<Button Grid.Column="2" Padding="2" Margin="0 -4 4 -4" Command="{Binding NewItem}">
<Button Grid.Column="2" Padding="2" Margin="0 -4 4 -4" Command="{Binding NewItem}" Name="NewScheme">
<Image Width="24" Height="24" Source="/Assets/NewItem.png"/>
</Button>
<Button Grid.Column="3" Padding="2" Margin="0 -4 0 -4" Command="{Binding Delete}" IsVisible="{Binding CanUseSchemeDeleter}">
Expand Down
1 change: 1 addition & 0 deletions LogicSimulator/for_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "Для тестирования", "created": 1683838621, "modified": 1683839324, "items": [{"id": 5, "pos": "$p$149,242", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$153,330", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$152,414", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 5, "pos": "$p$149,497", "size": "$s$75,75", "base_size": 25, "state": false}, {"id": 9, "pos": "$p$587,328", "size": "$s$105,105", "base_size": 25, "state": "0.1.0.1.0.0"}, {"id": 3, "pos": "$p$339,236", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$348,336", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$352,444", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$355,546", "size": "$s$90,90", "base_size": 25}, {"id": 9, "pos": "$p$594,460", "size": "$s$105,105", "base_size": 25, "state": "0.0.1.0.0.0"}, {"id": 3, "pos": "$p$591,182", "size": "$s$90,90", "base_size": 25}, {"id": 7, "pos": "$p$749,199", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$750,276", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,354", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,430", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$752,506", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$755,584", "size": "$s$75,75", "base_size": 25}, {"id": 1, "pos": "$p$592,596", "size": "$s$90,90", "base_size": 25}], "joins": [[0, 0, "Out", 5, 0, "In"], [1, 0, "Out", 6, 0, "In"], [2, 0, "Out", 7, 0, "In"], [3, 0, "Out", 8, 0, "In"], [4, 3, "Out", 6, 1, "In"], [11, 0, "In", 4, 3, "Out"], [4, 4, "Out", 10, 0, "In"], [12, 0, "In", 4, 4, "Out"], [13, 0, "In", 4, 5, "Out"], [4, 5, "Out", 17, 0, "In"], [4, 0, "In", 5, 2, "Out"], [6, 2, "Out", 4, 1, "In"], [6, 2, "Out", 9, 2, "In"], [7, 2, "Out", 4, 2, "In"], [7, 2, "Out", 9, 1, "In"], [8, 2, "Out", 9, 0, "In"], [9, 3, "Out", 10, 1, "In"], [14, 0, "In", 9, 3, "Out"], [15, 0, "In", 9, 4, "Out"], [9, 4, "Out", 17, 1, "In"], [16, 0, "In", 9, 5, "Out"], [9, 5, "Out", 7, 1, "In"], [10, 2, "Out", 5, 1, "In"], [17, 2, "Out", 8, 1, "In"]], "states": "00000100010000000000000"}
53 changes: 49 additions & 4 deletions UITestsLogicSimulator/AllTestsInOnePlace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private void Log(string? message) {
public AllTestsInOnePlace() {
var buttons = launcherWindow.GetVisualDescendants().OfType<Button>();
var new_proj = buttons.First(x => (string) x.Content == "Создать новый проект");
new_proj.Command.Execute(new_proj.CommandParameter);
new_proj.Command.Execute(null);
// Только таки имбовая возможность создать проект, но никогда не определять ему файл
// сохранения, от чего данные unit-test'ы никогда не появлияют на файловую систему :D

Expand All @@ -52,7 +52,7 @@ public AllTestsInOnePlace() {
var pos = new Point(x, y);
map.Press(target, pos);
int mode = map.Release(target, pos);
Log("Tapped: " + map.tapped + " | " + mode);
// Log("Tapped: " + map.tapped + " | " + mode);
if (map.tapped && mode == 1) {
var tpos = map.tap_pos;
var newy = map.GenSelectedItem();
Expand All @@ -66,7 +66,7 @@ private void Move(Control a, Control b) {
map.Move(a, new());
map.Press(a, new());
int mode = map.Release(b, new(100, 100), false); // В себе уже имеет map.Move(target, pos2)
Log("Moved: " + map.tapped + " | " + mode);
// Log("Moved: " + map.tapped + " | " + mode);
}
private string Export() {
map.Export();
Expand All @@ -87,6 +87,45 @@ private static void SaveProject() { // Чтобы только посмотре
proj.FileName = "tested";
proj.Save();
}
private void NewScheme() {
Export();
var button = mainWindow.GetVisualDescendants().OfType<Button>().Last(x => x.Name == "NewScheme");
button.Command.Execute(null);
var button2 = mainWindow.GetVisualDescendants().OfType<Button>().Last(x => x.Name == "OpenScheme");
button2.Command.Execute(null);
}
private void ImportScheme(string data) {
object yeah = Utils.Json2obj(data) ?? new Exception("Что-то не то в JSON");
var proj = ViewModelBase.TopSecretGetProj() ?? throw new Exception("А где проект? :/");
Scheme clone = new(proj, yeah);
var scheme = map.current_scheme ?? throw new Exception("А где схема? :/");
scheme.Update(clone.items, clone.joins, clone.states);
map.ImportScheme();
}



private string ComplexSolution() {
var sim = map.sim;
sim.ComparativeTestMode = true;

var inputs = sim.GetSwitches();
var outputs = sim.GetLightBulbs();
int L = inputs.Length;
int steps = 1 << L;

StringBuilder sb = new();
for (int step = 0; step < steps; step++) {
for (int i = 0; i < L; i++) inputs[i].SetState((step & 1 << i) > 0);
if (step > 0) sb.Append('|');
int hits = 0;
Ticks(1);
while (hits++ < 1024 && sim.SomethingHasChanged) Ticks(1);
foreach (var output in outputs) sb.Append(output.GetState() ? '1' : '0');
sb.Append("_t" + hits);
}
return sb.ToString();
}



Expand Down Expand Up @@ -153,10 +192,16 @@ public void GeneralTest() {
}
Assert.Equal("00000|00111|11000|00111|11000|00111|11011|11000", sb.ToString());

NewScheme();
Task.Delay(1).GetAwaiter().GetResult();

ImportScheme("{\"name\": \"Для тестирования\", \"created\": 1683838621, \"modified\": 1683839324, \"items\": [{\"id\": 5, \"pos\": \"$p$149,242\", \"size\": \"$s$75,75\", \"base_size\": 25, \"state\": false}, {\"id\": 5, \"pos\": \"$p$153,330\", \"size\": \"$s$75,75\", \"base_size\": 25, \"state\": false}, {\"id\": 5, \"pos\": \"$p$152,414\", \"size\": \"$s$75,75\", \"base_size\": 25, \"state\": false}, {\"id\": 5, \"pos\": \"$p$149,497\", \"size\": \"$s$75,75\", \"base_size\": 25, \"state\": false}, {\"id\": 9, \"pos\": \"$p$587,328\", \"size\": \"$s$105,105\", \"base_size\": 25, \"state\": \"0.1.0.1.0.0\"}, {\"id\": 3, \"pos\": \"$p$339,236\", \"size\": \"$s$90,90\", \"base_size\": 25}, {\"id\": 3, \"pos\": \"$p$348,336\", \"size\": \"$s$90,90\", \"base_size\": 25}, {\"id\": 3, \"pos\": \"$p$352,444\", \"size\": \"$s$90,90\", \"base_size\": 25}, {\"id\": 3, \"pos\": \"$p$355,546\", \"size\": \"$s$90,90\", \"base_size\": 25}, {\"id\": 9, \"pos\": \"$p$594,460\", \"size\": \"$s$105,105\", \"base_size\": 25, \"state\": \"0.0.1.0.0.0\"}, {\"id\": 3, \"pos\": \"$p$591,182\", \"size\": \"$s$90,90\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$749,199\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$750,276\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$751,354\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$751,430\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$752,506\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 7, \"pos\": \"$p$755,584\", \"size\": \"$s$75,75\", \"base_size\": 25}, {\"id\": 1, \"pos\": \"$p$592,596\", \"size\": \"$s$90,90\", \"base_size\": 25}], \"joins\": [[0, 0, \"Out\", 5, 0, \"In\"], [1, 0, \"Out\", 6, 0, \"In\"], [2, 0, \"Out\", 7, 0, \"In\"], [3, 0, \"Out\", 8, 0, \"In\"], [4, 3, \"Out\", 6, 1, \"In\"], [11, 0, \"In\", 4, 3, \"Out\"], [4, 4, \"Out\", 10, 0, \"In\"], [12, 0, \"In\", 4, 4, \"Out\"], [13, 0, \"In\", 4, 5, \"Out\"], [4, 5, \"Out\", 17, 0, \"In\"], [4, 0, \"In\", 5, 2, \"Out\"], [6, 2, \"Out\", 4, 1, \"In\"], [6, 2, \"Out\", 9, 2, \"In\"], [7, 2, \"Out\", 4, 2, \"In\"], [7, 2, \"Out\", 9, 1, \"In\"], [8, 2, \"Out\", 9, 0, \"In\"], [9, 3, \"Out\", 10, 1, \"In\"], [14, 0, \"In\", 9, 3, \"Out\"], [15, 0, \"In\", 9, 4, \"Out\"], [9, 4, \"Out\", 17, 1, \"In\"], [16, 0, \"In\", 9, 5, \"Out\"], [9, 5, \"Out\", 7, 1, \"In\"], [10, 2, \"Out\", 5, 1, \"In\"], [17, 2, \"Out\", 8, 1, \"In\"]], \"states\": \"00000000000000000000000\"}");
var res = ComplexSolution();
Assert.Equal("110001_t4|001010_t10|111011_t8|011011_t5|100100_t9|011111_t10|101110_t8|001110_t5|010001_t6|110001_t5|001110_t11|111111_t8|000100_t8|100100_t5|011011_t11|101010_t8", res);

Log("Export: " + Export());
Log("ОК!");
// SaveProject();
SaveProject();
}
}
}
14 changes: 1 addition & 13 deletions UITestsLogicSimulator/TestLog.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
Tapped: True | 1
Tapped: True | 1
Moved: False | 6
Tapped: True | 1
Tapped: True | 1
Tapped: True | 1
Moved: False | 6
Moved: False | 6
Moved: False | 6
Tapped: True | 1
Moved: False | 6
Sim: 00000|00111|11000|00111|11000|00111|11011|11000
Export: {"name": "Newy", "created": 123, "modified": 456, "items": [{"id": 0, "pos": "$p$200,200", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$300,300", "size": "$s$90,90", "base_size": 25}, {"id": 5, "pos": "$p$100,150", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 5, "pos": "$p$100,250", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 5, "pos": "$p$100,350", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 7, "pos": "$p$400,300", "size": "$s$75,75", "base_size": 25}], "joins": [[0, 2, "Out", 1, 0, "In"], [1, 2, "Out", 5, 0, "In"], [2, 0, "Out", 0, 0, "In"], [3, 0, "Out", 0, 1, "In"], [4, 0, "Out", 1, 1, "In"]], "states": "010111"}
Export: {"name": "Newy", "created": 123, "modified": 456, "items": [{"id": 5, "pos": "$p$149,242", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 5, "pos": "$p$153,330", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 5, "pos": "$p$152,414", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 5, "pos": "$p$149,497", "size": "$s$75,75", "base_size": 25, "state": true}, {"id": 9, "pos": "$p$587,328", "size": "$s$105,105", "base_size": 25, "state": "1.0.1.1.0.1"}, {"id": 3, "pos": "$p$339,236", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$348,336", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$352,444", "size": "$s$90,90", "base_size": 25}, {"id": 3, "pos": "$p$355,546", "size": "$s$90,90", "base_size": 25}, {"id": 9, "pos": "$p$594,460", "size": "$s$105,105", "base_size": 25, "state": "0.1.0.0.1.0"}, {"id": 3, "pos": "$p$591,182", "size": "$s$90,90", "base_size": 25}, {"id": 7, "pos": "$p$749,199", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$750,276", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,354", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$751,430", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$752,506", "size": "$s$75,75", "base_size": 25}, {"id": 7, "pos": "$p$755,584", "size": "$s$75,75", "base_size": 25}, {"id": 1, "pos": "$p$592,596", "size": "$s$90,90", "base_size": 25}], "joins": [[0, 0, "Out", 5, 0, "In"], [1, 0, "Out", 6, 0, "In"], [2, 0, "Out", 7, 0, "In"], [3, 0, "Out", 8, 0, "In"], [4, 3, "Out", 6, 1, "In"], [11, 0, "In", 4, 3, "Out"], [4, 4, "Out", 10, 0, "In"], [12, 0, "In", 4, 4, "Out"], [13, 0, "In", 4, 5, "Out"], [4, 5, "Out", 17, 0, "In"], [4, 0, "In", 5, 2, "Out"], [6, 2, "Out", 4, 1, "In"], [6, 2, "Out", 9, 2, "In"], [7, 2, "Out", 4, 2, "In"], [7, 2, "Out", 9, 1, "In"], [8, 2, "Out", 9, 0, "In"], [9, 3, "Out", 10, 1, "In"], [14, 0, "In", 9, 3, "Out"], [15, 0, "In", 9, 4, "Out"], [9, 4, "Out", 17, 1, "In"], [16, 0, "In", 9, 5, "Out"], [9, 5, "Out", 7, 1, "In"], [10, 2, "Out", 5, 1, "In"], [17, 2, "Out", 8, 1, "In"]], "states": "01111101101001001000000"}
ОК!
56 changes: 54 additions & 2 deletions UITestsLogicSimulator/tested
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Dict name="Новый проект" created="$1683838478" modified="$1683838479">
<Dict name="Новый проект" created="$1683843178" modified="$1683843179">
<schemes>
<List>
<Dict name="Newy" created="$123" modified="$1683838479" states="010111">
<Dict name="Newy" created="$123" modified="$456" states="010111">
<items>
<List>
<Dict id="$0" pos="$p$200,200" size="$s$90,90" base_size="$25"/>
Expand All @@ -23,6 +23,58 @@
</List>
</joins>
</Dict>
<Dict name="Newy" created="$123" modified="$456" states="01111101101001001000000">
<items>
<List>
<Dict id="$5" pos="$p$149,242" size="$s$75,75" base_size="$25" state="_BOOL_yeah"/>
<Dict id="$5" pos="$p$153,330" size="$s$75,75" base_size="$25" state="_BOOL_yeah"/>
<Dict id="$5" pos="$p$152,414" size="$s$75,75" base_size="$25" state="_BOOL_yeah"/>
<Dict id="$5" pos="$p$149,497" size="$s$75,75" base_size="$25" state="_BOOL_yeah"/>
<Dict id="$9" pos="$p$587,328" size="$s$105,105" base_size="$25" state="1.0.1.1.0.1"/>
<Dict id="$3" pos="$p$339,236" size="$s$90,90" base_size="$25"/>
<Dict id="$3" pos="$p$348,336" size="$s$90,90" base_size="$25"/>
<Dict id="$3" pos="$p$352,444" size="$s$90,90" base_size="$25"/>
<Dict id="$3" pos="$p$355,546" size="$s$90,90" base_size="$25"/>
<Dict id="$9" pos="$p$594,460" size="$s$105,105" base_size="$25" state="0.1.0.0.1.0"/>
<Dict id="$3" pos="$p$591,182" size="$s$90,90" base_size="$25"/>
<Dict id="$7" pos="$p$749,199" size="$s$75,75" base_size="$25"/>
<Dict id="$7" pos="$p$750,276" size="$s$75,75" base_size="$25"/>
<Dict id="$7" pos="$p$751,354" size="$s$75,75" base_size="$25"/>
<Dict id="$7" pos="$p$751,430" size="$s$75,75" base_size="$25"/>
<Dict id="$7" pos="$p$752,506" size="$s$75,75" base_size="$25"/>
<Dict id="$7" pos="$p$755,584" size="$s$75,75" base_size="$25"/>
<Dict id="$1" pos="$p$592,596" size="$s$90,90" base_size="$25"/>
</List>
</items>
<joins>
<List>
<List _0='$0' _1='$0' _2='Out' _3='$5' _4='$0' _5='In'/>
<List _0='$1' _1='$0' _2='Out' _3='$6' _4='$0' _5='In'/>
<List _0='$2' _1='$0' _2='Out' _3='$7' _4='$0' _5='In'/>
<List _0='$3' _1='$0' _2='Out' _3='$8' _4='$0' _5='In'/>
<List _0='$4' _1='$3' _2='Out' _3='$6' _4='$1' _5='In'/>
<List _0='$11' _1='$0' _2='In' _3='$4' _4='$3' _5='Out'/>
<List _0='$4' _1='$4' _2='Out' _3='$10' _4='$0' _5='In'/>
<List _0='$12' _1='$0' _2='In' _3='$4' _4='$4' _5='Out'/>
<List _0='$13' _1='$0' _2='In' _3='$4' _4='$5' _5='Out'/>
<List _0='$4' _1='$5' _2='Out' _3='$17' _4='$0' _5='In'/>
<List _0='$4' _1='$0' _2='In' _3='$5' _4='$2' _5='Out'/>
<List _0='$6' _1='$2' _2='Out' _3='$4' _4='$1' _5='In'/>
<List _0='$6' _1='$2' _2='Out' _3='$9' _4='$2' _5='In'/>
<List _0='$7' _1='$2' _2='Out' _3='$4' _4='$2' _5='In'/>
<List _0='$7' _1='$2' _2='Out' _3='$9' _4='$1' _5='In'/>
<List _0='$8' _1='$2' _2='Out' _3='$9' _4='$0' _5='In'/>
<List _0='$9' _1='$3' _2='Out' _3='$10' _4='$1' _5='In'/>
<List _0='$14' _1='$0' _2='In' _3='$9' _4='$3' _5='Out'/>
<List _0='$15' _1='$0' _2='In' _3='$9' _4='$4' _5='Out'/>
<List _0='$9' _1='$4' _2='Out' _3='$17' _4='$1' _5='In'/>
<List _0='$16' _1='$0' _2='In' _3='$9' _4='$5' _5='Out'/>
<List _0='$9' _1='$5' _2='Out' _3='$7' _4='$1' _5='In'/>
<List _0='$10' _1='$2' _2='Out' _3='$5' _4='$1' _5='In'/>
<List _0='$17' _1='$2' _2='Out' _3='$8' _4='$1' _5='In'/>
</List>
</joins>
</Dict>
</List>
</schemes>
</Dict>
2 changes: 1 addition & 1 deletion build.num
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1078
1089

0 comments on commit 11d3cc6

Please sign in to comment.