tests/DotNetCommon.Test/RandomHelperTests.cs

(完整代码) 1KB

using DotNetCommon.Test.Extensions;
using NUnit.Framework;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetCommon.Extensions;

namespace DotNetCommon.Test
{
    [TestFixture]
    public class RandomHelperTests
    {
        [Test]
        public void RandomTest()
        {
            List<int> ints = new List<int>();
            100.Times(() =>
            {
                var r = RandomHelper.Next(1, 10);
                ints.Add(r);
                r.ShouldBeInRange(1, 10);
                ints.Count(_ => _ == r).ShouldBeLessThan(Math.Max(ints.Count, 10));
                var r2 = RandomHelper.Next(10);
                ints.Add(r2);
                r2.ShouldBeLessThan(10);
                ints.Count(_ => _ == r2).ShouldBeLessThan(Math.Max(ints.Count, 10));
            });

            List<double> doubles = new List<double>();
            100.Times(() =>
            {
                var r = RandomHelper.Next(-10, 100.53);
                doubles.Add(r);
                r.ShouldBeInRange(-10, 100.53);
                doubles.Count(_ => _ == r).ShouldBeLessThan(Math.Max(doubles.Count, 10));
                var r2 = RandomHelper.Next(100.53);
                doubles.Add(r2);
                r2.ShouldBeLessThan(100.53);
                doubles.Count(_ => _ == r2).ShouldBeLessThan(Math.Max(doubles.Count, 10));
            });

        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。