Click here to Skip to main content
15,435,743 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: IDE drives (hard or otherwise) Pin
Gerry Schmitz28-Jan-22 6:29
mveGerry Schmitz28-Jan-22 6:29 
GeneralRe: IDE drives (hard or otherwise) Pin
jeron128-Jan-22 6:40
Memberjeron128-Jan-22 6:40 
GeneralRe: IDE drives (hard or otherwise) Pin
Matias Lopez28-Jan-22 8:22
MemberMatias Lopez28-Jan-22 8:22 
GeneralRe: IDE drives (hard or otherwise) Pin
CodeWraith28-Jan-22 19:46
MemberCodeWraith28-Jan-22 19:46 
GeneralRe: IDE drives (hard or otherwise) Pin
kmoorevs28-Jan-22 10:45
Memberkmoorevs28-Jan-22 10:45 
GeneralRe: IDE drives (hard or otherwise) Pin
#realJSOP29-Jan-22 1:58
mva#realJSOP29-Jan-22 1:58 
GeneralRe: IDE drives (hard or otherwise) Pin
CodeWraith29-Jan-22 6:15
MemberCodeWraith29-Jan-22 6:15 
GeneralOK so, I'm trying Unit Tests. Pin
OriginalGriff28-Jan-22 3:17
mveOriginalGriff28-Jan-22 3:17 
Just using the VS built in stuff, and I've migrated all my Range tests (with a couple added to cover cases I'd missed Blush | :O ).
I kinda like it:
C#
using System;
using NonContiguousRange;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace RangeTests
    {
    [TestClass]
    public class RangeTester
        {
        // Useful test constructors:
        private Range ra = new Range(0, 4);       // 
        private Range rb = new Range(5, 9);       // Contiguous with ra
        private Range rc = new Range(10, 14);     // Contiguous with rb
        private Range rd = new Range(1, 3);       // Intersects ra, not contiguous with rb
        private Range re = new Range(6, 8);       // Intersects rb, not contiguous with rc
        private Range rf = new Range(16, 19);     // Not contiguous with anything.
        private Range rg = new Range(0, 0);       // Single element.
        private Range rh = new Range(1, 1);       // Single element.
        private Range ri = new Range(2, 2);       // Single element.
        private Range rj = new Range(0, 19);      // All elements.
        private Range rk = new Range(0, 4);       // Identical to ra
        private Range rl = new Range(-1, 1);      // Overlap start ra
        private Range rm = new Range(3, 5);       // Overlap end ra
        private string testType = "";

        #region Tests
        [TestMethod]
        public void ConstructorsTest()
            {
            testType = "\nConstructor";
            Assert.AreEqual(5, ra.Count, 0, $"{testType}: Range items count incorrect");
            Assert.AreEqual(0, ra.Min, 0, $"{testType}: Range minimum incorrect");
            Assert.AreEqual(4, ra.Max, 0, $"{testType}: Range maximum incorrect");
            Check(ra, new int[] { 0, 1, 2, 3, 4 }, "Wrong elements");
            Check(new Range(new int[] { 0, 1, 2, 5, 6, 7 }.AsEnumerable()), new int[] { 0, 1, 2, 5, 6, 7 }, "Enumerable parameter wrong elements");
            }
        [TestMethod]
        public void HumanReadabilityTest()
            {
            testType = "\nHuman Readability";
            Assert.AreEqual("(0:4)", ra.ToString(), false, $"{testType}: Contiguous range incorrect");
            Assert.AreEqual("(0:4) | (6:8)", ra.UnionWith(re).ToString(), false, $"{testType}: Noncontiguous range incorrect");
            }
        [TestMethod]
        public void Emptyness()
            {
            testType = "\nEmptiness";
            Assert.IsTrue(Enumerable.SequenceEqual(Range.GetEmpty(), new int[0]), $"{testType}: Empty isn't");
            }
        [TestMethod]
        public void Unions()
            {
            testType = "\nUnions";
            Check(ra.UnionWith(ra), new int[] { 0, 1, 2, 3, 4 }, "Self union");
            Check(ra.UnionWith(rb), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "Contiguous 1");
            Check(rb.UnionWith(rc), new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, "Contiguous 2");
            Check(ra.UnionWith(rc), new int[] { 0, 1, 2, 3, 4, 10, 11, 12, 13, 14 }, "Noncontiguous 1");
            Check(ra.UnionWith(re), new int[] { 0, 1, 2, 3, 4, 6, 7, 8 }, "Noncontiguous 2");
            Check(ra.UnionWith(rg), new int[] { 0, 1, 2, 3, 4 }, "Single element in original range");
            Check(rd.UnionWith(rg), new int[] { 0, 1, 2, 3 }, "Single element contiguous");
            Check(rb.UnionWith(rg), new int[] { 0, 5, 6, 7, 8, 9 }, "Single element noncontiguous");
            Check(rg.UnionWith(rh).UnionWith(ri), new int[] { 0, 1, 2 }, "Three single element contiguous");
            Assert.AreEqual(10, ra.UnionWith(rc).Count, 0, $"{testType}: Count");
            Assert.AreEqual(0, ra.UnionWith(rc).Min, 0, $"{testType}: Minimum value");
            Assert.AreEqual(14, ra.UnionWith(rc).Max, 0, $"{testType}: Maximum value");
            }
        [TestMethod]
        public void Intersections()
            {
            testType = "\nIntersections";
            Check(ra.Intersecting(ra), new int[] { 0, 1, 2, 3, 4 }, "Self");
            Check(ra.Intersecting(rl), new int[] { 0, 1 }, "Left intersection");
            Check(ra.Intersecting(rd), new int[] { 1, 2, 3 }, "Center intersection");
            Check(ra.Intersecting(rm), new int[] { 3, 4 }, "Right intersection");
            Check(ra.Intersecting(rb), new int[0], "Contiguous 1");
            Check(rb.Intersecting(rc), new int[0], "Contiguous 2");
            Check(ra.Intersecting(rc), new int[0], "Noncontiguous, non-intersecting");
            Check(ra.Intersecting(rg), new int[] { 0 }, "Single element, intersecting");
            Check(rb.Intersecting(rg), new int[0], "Single element, non-intersecting");
            Check(rg.Intersecting(rh).Intersecting(ri), new int[0], "Single element, single element");
            }
        [TestMethod]
        public void Exceptions()
            {
            testType = "\nExceptions";
            Check(ra.Excepting(ra), new int[0], "Self");
            Check(ra.Excepting(rl), new int[] { 2, 3, 4 }, "Left intersection");
            Check(ra.Excepting(rd), new int[] { 0, 4 }, "Center intersection");
            Check(ra.Excepting(rm), new int[] { 0, 1, 2 }, "Right intersection");
            Check(ra.Excepting(rb), new int[] { 0, 1, 2, 3, 4 }, "Contiguous 1");
            Check(rb.Excepting(rc), new int[] { 5, 6, 7, 8, 9 }, "Contiguous 2");
            Check(ra.Excepting(rc), new int[] { 0, 1, 2, 3, 4 }, "Noncontiguous");
            Check(ra.Excepting(rg), new int[] { 1, 2, 3, 4 }, "Single Element, intersecting 1");
            Check(rj.Excepting(rh).Excepting(rb).Excepting(rf), new int[] { 0, 2, 3, 4, 10, 11, 12, 13, 14, 15 }, "Multiple");
            Check(rg.Excepting(rh).Excepting(ri), new int[] { 0 }, "Multiple single element");
            }
        [TestMethod]
        public void Miscellaneous()
            {
            testType = "\nMiscellaneous";
            Range nc = ra.UnionWith(rf);        // Non contiguous, (0:4) | (16, 19)
            Check(ra.EndAt(19), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, "Expand right, contiguous");
            Check(rf.StartAt(0), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, "Expand left, contiguous");
            Check(nc.EndAt(9), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, "Contract right, non-contiguous");
            Check(nc.StartAt(9), new int[] { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, "Contract left, non-contiguous");
            Check(ra.UnionWith(re).MakeContiguous(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, "Make contiguous");
            }
        [TestMethod]
        public void AddToRange()
            {
            testType = "\nAdding to";
            Check(ra.Add(5), new int[] { 0, 1, 2, 3, 4, 5 }, "Single, right");
            Check(ra.Add(-1), new int[] { -1, 0, 1, 2, 3, 4 }, "Single, left");
            Check(ra.AddRange(new int[] { 5, -1 }), new int[] { -1, 0, 1, 2, 3, 4, 5 }, "Array");
            Check(ra + 5, new int[] { 0, 1, 2, 3, 4, 5 }, "Operator +, single, right");
            Check(ra + -1, new int[] { -1, 0, 1, 2, 3, 4 }, "Operator +, single, left");
            Check(ra + new int[] { 5, -1 }, new int[] { -1, 0, 1, 2, 3, 4, 5 }, "Operator +, array");
            Check(ra + rb, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, "Operator +, range");
            }
        [TestMethod]
        public void RemoveFromRange()
            {
            testType = "\nRemove from range";
            Check(ra.Remove(0), new int[] { 1, 2, 3, 4 }, "Single, left");
            Check(ra.Remove(2), new int[] { 0, 1, 3, 4 }, "Single, center");
            Check(ra.Remove(4), new int[] { 0, 1, 2, 3 }, "Single, right");
            Check(ra.RemoveRange(new int[] { 0, 1 }), new int[] { 2, 3, 4 }, "Array, left");
            Check(ra.RemoveRange(new int[] { 2, 3 }), new int[] { 0, 1, 4 }, "Array, center");
            Check(ra.RemoveRange(new int[] { 3, 4 }), new int[] { 0, 1, 2 }, "Array, right");
            Check(ra - 1, new int[] { 0, 2, 3, 4 }, "Operator -, single");
            Check(ra - -1, new int[] { 0, 1, 2, 3, 4 }, "Operator -, single, not included");
            Check(ra - new int[] { 1, 2 }, new int[] { 0, 3, 4 }, "Operator -, array");
            Check(ra - rd, new int[] { 0, 4 }, "Operator -, range");
            }
        [TestMethod]
        public void Comparisons()
            {
            testType = "\nComparisons";
            Assert.IsTrue(ra.Equals(rk), "Equals");
            Assert.IsTrue(ra.Equals((object)rk), "Equals (object)");
            Assert.IsTrue(ra == rk, "==");
            Assert.IsFalse(ra != rk, "!=");
            }
        [TestMethod]
        public void Contiguousness()
            {
            testType = "\nContiguousness";
            Assert.IsTrue(ra.IsContiguousWith(rb), "Contiguous, right");
            Assert.IsTrue(rb.IsContiguousWith(ra), "Contiguous, left");
            Assert.IsFalse(ra.IsContiguousWith(rc), "NonContiguous, right");
            Assert.IsFalse(re.IsContiguousWith(rd), "Noncontiguous, left");
            }
        [TestMethod]
        public void Intersectivity()
            {
            testType = "\nIntersectivity";
            Assert.IsFalse(ra.IsIntersecting(rb), "Non-intersecting, right");
            Assert.IsFalse(rb.IsIntersecting(ra), "Non-intersecting, left");
            Assert.IsTrue(ra.IsIntersecting(rm), "Intersecting, right");
            Assert.IsTrue(ra.IsIntersecting(rd), "Intersecting, center");
            Assert.IsTrue(rm.IsIntersecting(ra), "Intersecting, left");
            }
        #endregion

        #region Support functions
        /// <summary>
        /// Check a Range result
        /// </summary>
        /// <param name="result"></param>
        /// <param name="expected"></param>
        /// <param name="desc"></param>
        private void Check(Range range, int[] expected, string desc)
            {
            string result = "Range length incorrect";
            if (range.Count == expected.Length)
                {
                result = "Range values did not match";
                if (Enumerable.SequenceEqual(range, expected))
                    {
                    return;
                    }
                }
            ReportFailure(desc, result, range, expected);
            }
        /// <summary>
        /// Report a failure
        /// </summary>
        /// <param name="desc"></param>
        /// <param name="result"></param>
        /// <param name="range"></param>
        /// <param name="expected"></param>
        private void ReportFailure(string desc, string result, string range, string expected)
            {
            Assert.IsTrue(false, $"{testType}: {desc} - {result}\n   Got     : {range}\n   Expected: {expected}");
            }
        /// <summary>
        /// Report a failure
        /// </summary>
        /// <param name="desc"></param>
        /// <param name="result"></param>
        /// <param name="range"></param>
        /// <param name="expected"></param>
        private void ReportFailure(string desc, string result, Range range, int[] expected)
            {
            Assert.IsTrue(false, $"{testType}: {desc} - {result}\n   Got     : {string.Join(", ", range.Select(r => r.ToString()))}\n   Expected: {string.Join(", ", expected.Select(r => r.ToString()))}");
            }
        #endregion
        }
    }
So I thought I'd move to the next step: autogenerating test stubs.

Right click in my project code, and select "Create Unit Tests" expecting ... well, not a lot, but something usable.
All I get is a message box:
MessageBox
Value cannot be null. 
Parameter name: codeClass.
Off to Google ... and lo: Create unit test command fails in STRUCTS[^]
It's a bug that was reported in 2018, and closed a couple of months later with no action. Sigh | :sigh:

Truely, MS do not like to fix bugs - just change the icons and ship it ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

GeneralRe: OK so, I'm trying Unit Tests. Pin
Richard Andrew x6428-Jan-22 3:49
professionalRichard Andrew x6428-Jan-22 3:49 
GeneralRe: OK so, I'm trying Unit Tests. Pin
honey the codewitch28-Jan-22 5:53
mvahoney the codewitch28-Jan-22 5:53 
GeneralRe: OK so, I'm trying Unit Tests. Pin
TNCaver28-Jan-22 6:21
MemberTNCaver28-Jan-22 6:21 
GeneralWSO CCC OTD 2022-01-28 Solution Pin
OriginalGriff28-Jan-22 2:19
mveOriginalGriff28-Jan-22 2:19 
GeneralRe: WSO CCC OTD 2022-01-28 Solution Pin
pkfox28-Jan-22 3:36
professionalpkfox28-Jan-22 3:36 
GeneralIDE Hard Drives Pin
milo-xml28-Jan-22 2:08
professionalmilo-xml28-Jan-22 2:08 
GeneralRe: IDE Hard Drives Pin
Peter_in_278028-Jan-22 2:15
professionalPeter_in_278028-Jan-22 2:15 
GeneralRe: IDE Hard Drives Pin
milo-xml28-Jan-22 4:46
professionalmilo-xml28-Jan-22 4:46 
GeneralRe: IDE Hard Drives Pin
Peter_in_278028-Jan-22 11:45
professionalPeter_in_278028-Jan-22 11:45 
GeneralRe: IDE Hard Drives Pin
OriginalGriff28-Jan-22 2:27
mveOriginalGriff28-Jan-22 2:27 
GeneralRe: IDE Hard Drives Pin
milo-xml28-Jan-22 4:49
professionalmilo-xml28-Jan-22 4:49 
GeneralRe: IDE Hard Drives Pin
ElectronProgrammer28-Jan-22 11:02
MemberElectronProgrammer28-Jan-22 11:02 
GeneralRe: IDE Hard Drives Pin
milo-xml29-Jan-22 5:59
professionalmilo-xml29-Jan-22 5:59 
GeneralRe: IDE Hard Drives Pin
dandy7228-Jan-22 4:43
Memberdandy7228-Jan-22 4:43 
GeneralRe: IDE Hard Drives Pin
milo-xml28-Jan-22 4:49
professionalmilo-xml28-Jan-22 4:49 
GeneralRe: IDE Hard Drives Pin
dandy7228-Jan-22 5:34
Memberdandy7228-Jan-22 5:34 
GeneralRe: IDE Hard Drives Pin
milo-xml28-Jan-22 5:52
professionalmilo-xml28-Jan-22 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

When building an application, when is the most important time to consider the User Experience?
They are the ones we write code for, right?
  Results   209 votes