<commit_before>﻿using System;
using System.Collections.Generic;
using System.Windows;
using Xunit;

namespace Caliburn.Micro.WPF.Tests
{
    public class ScopeNamingRouteTests
    {
        [Fact]
        public void CorrectlyGetsAddedHop()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            route.AddHop(d1, d2);
            DependencyObject target;
            var result = route.TryGetHop(d1, out target);
            Assert.True(result);
            Assert.Same(d2, target);
        }

        [Fact]
        public void PreventsRoutingCycles()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            route.AddHop(d1, d2);
            route.AddHop(d2, d3);
            route.AddHop(d3, d4);
            Assert.Throws<ArgumentException>(() => route.AddHop(d4, d1));
        }

        [Fact]
        public void GetsAllHopsAdded()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            route.AddHop(d1, d2);
            route.AddHop(d2, d3);
            route.AddHop(d3, d4);

            var all = new List<DependencyObject> { d2, d3, d4 };

            var source = d1;
            DependencyObject target;

            while (route.TryGetHop(source, out target))
            {
                all.Remove(target);
                source = target;
            }

            Assert.Empty(all);
        }

        [Fact]
        public void CannotAddDisjointHops()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            // d1 -> d2 and d3 -> d4, but d2 doesn't lead to d3, so d3 -> d4 is rejected
            route.AddHop(d1, d2);
            Assert.Throws<ArgumentException>(() => route.AddHop(d3, d4));
        }

        [Fact]
        public void RootMustBePartOfPathIfAnyHops()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();

            route.AddHop(d1, d2);
            Assert.Throws<ArgumentException>(() => route.Root = new DependencyObject());
        }

        [Fact]
        public void RootCanBeSetIfNoHops()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var root = new DependencyObject();
            route.Root = root;
            Assert.Same(root, route.Root);
        }

        [Fact]
        public void RootMustNotBeAHopTarget()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();<commit_msg>Remove uneeded test from #184<commit_after>﻿using System;
using System.Collections.Generic;
using System.Windows;
using Xunit;

namespace Caliburn.Micro.WPF.Tests
{
    public class ScopeNamingRouteTests
    {
        [Fact]
        public void CorrectlyGetsAddedHop()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            route.AddHop(d1, d2);
            DependencyObject target;
            var result = route.TryGetHop(d1, out target);
            Assert.True(result);
            Assert.Same(d2, target);
        }

        [Fact]
        public void PreventsRoutingCycles()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            route.AddHop(d1, d2);
            route.AddHop(d2, d3);
            route.AddHop(d3, d4);
            Assert.Throws<ArgumentException>(() => route.AddHop(d4, d1));
        }

        [Fact]
        public void GetsAllHopsAdded()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            route.AddHop(d1, d2);
            route.AddHop(d2, d3);
            route.AddHop(d3, d4);

            var all = new List<DependencyObject> { d2, d3, d4 };

            var source = d1;
            DependencyObject target;

            while (route.TryGetHop(source, out target))
            {
                all.Remove(target);
                source = target;
            }

            Assert.Empty(all);
        }

        [Fact]
        public void CannotAddDisjointHops()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
            var d4 = new DependencyObject();

            // d1 -> d2 and d3 -> d4, but d2 doesn't lead to d3, so d3 -> d4 is rejected
            route.AddHop(d1, d2);
            Assert.Throws<ArgumentException>(() => route.AddHop(d3, d4));
        }

        [Fact]
        public void RootCanBeSetIfNoHops()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var root = new DependencyObject();
            route.Root = root;
            Assert.Same(root, route.Root);
        }

        [Fact]
        public void RootMustNotBeAHopTarget()
        {
            var route = new BindingScope.ScopeNamingRoute();
            var d1 = new DependencyObject();
            var d2 = new DependencyObject();
            var d3 = new DependencyObject();
{'fraction_non_alphanumeric': 0.09869164916814731, 'fraction_numerical': 0.017606202552091745, 'mean_word_length': 1.639386189258312, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6342166', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1685, 'n_words': 435}