Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 220941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:59:11+00:00 2026-05-11T18:59:11+00:00

I have the following test which seems to produce same strings but Assert.AreEqual fails.

  • 0

I have the following test which seems to produce same strings but Assert.AreEqual fails.

[TestMethod]
public void Decompressed_test_should_equal_to_text_before_compression()
{
    TextCompressor compressor = new TextCompressor();
    Random r = new Random((int)DateTime.Now.Ticks);

    for (int i = 500; i < 1500; i++)
    {
        char[] testArray = new char[i];

        for (int j = 0; j < i; j++)
        {                    
            char randomChar = (char)(r.Next(256, 65536));
            testArray[j] = randomChar;
        }
        string testString = new String(testArray);
        string compressed = compressor.Compress(testString);
        string decompressed = compressor.Decompress(compressed);

        Assert.AreEqual(testString.Length, decompressed.Length);
        Assert.AreEqual(testString, decompressed, false, CultureInfo.InvariantCulture);
    }
}

compressor.Compress and compressor.Decompress does some compression and decompression with GZipStream.

It passes if I try (65, 90) instead of (256, 65536) so I am guessing it has something to do with unicode. I tried CurrentCulture and no culture at all instead of InvariantCulture and it still fails. But the resulting strings appear to be the same:

Assert.AreEqual failed.

Expected:

<☔ฺ疉鎷얚�᧏跨꿌沩얫嘹֨ز항們嵜浮䑹ﴰ靄斳薃픢萁⯬쫎ʛ�⫕蝺ꄗ穌넢뇌䶆멊큀퉆䐫̥괊⑆놸僥̅ᵀ㣚ꢅ뺓䇚녚伀讍홬䈕�캾撏Ჴ孢黮摠뮡䌦윃ᬳ狚䆙툾훶䏤ꛈṻ⟧㉖鮸蒵萗냤퇅서㪨瀲鰪残䓴ﯘ넃櫜㑦䢻쮓죣䕱䶘㴝姳뿝嘼ᷨ㗬꺬櫣涷꠶浒껅က㷕䩉毎覛�⧹䮯嬇힚艐Ὑ쇕횻鸙蹻硐���䈆쓖⸛錼鰙ኰ乒֐⺴썓힠䵓ꅄⵈ桃怅㾈枟⏠ﻪ폫ﺍ琖ퟰ乼�쩐鑈푷᫇﯎蕱늛�쭡�䙠ⲓᒇꪮ툅⃑ꦴ돻♹ᢋ麝熪뚭Ћ䌚�娯钮⡃㪿ᅰ⤩㥍車䎘磛蚾ㅸ擫떦蝳分鰽䠺ꭍ튘폻⥽ⳉ历⹼驿똮�⯴⋟Ḋ᛼룴꣜墭䐣앾郢�ᵸᮄ杗奪騑硼佑烑鄗䳘핬溴墽炁ࣘヲ栥풼ಃ斗狹就쵎⃺嬒瀃碂밎崹䎐貇஛汫踖�뢸숥퍞르뗿䭯䖝䱅�䵱꽔븽䢴ꁅ⟼�蒠癸ꩽ靔临䚝﹗⩏￸鍁Ꮨ䷇쁐쨒ʊ쪦鄭借滋铆ᮉ嚃ᩨ⶝ိ펇ꮼ뇄』ᰉ㕾枒鯅蛺䠿櫄築픆车똅렬㈆ﹼἋ荞괋랆偦뤰䝷핸⹝屑素蝨怀猔勛碉퀪睹�Ⓥ䍙ಗ䤮뾿谢ꁼ戻ﮖᆯ콧偪ﺯ븭碇쮢籍⁜왋壝駡暷샖଄ࣵ艫᜝䃴厫ᢉ慨䁆ꂴ೉溘欋옭螶䦗跠﨔膉痹邘⋫吪멚埣ꯕ扌옘广犵肖街�㶕畅몡ↇ꠫襤픧ၥ帻놤ਰ惘똞颤糴쫼鿋䬝穫⺁峁踷锝副鰀嗊⹀谲遲�䩢푑팾��糔뭯዇ࣷ䷴䬾갭ⶵ᾿틩魨㵻恬҅པᣄⲪ豩뛌꛵㥨몙〼△⏮큤�亃ꢡ웼ఐ칇뻻펂㢓吋䂃䨠䕱>.

Actual:

<☔ฺ疉鎷얚�᧏跨꿌沩얫嘹֨ز항們嵜浮䑹ﴰ靄斳薃픢萁⯬쫎ʛ�⫕蝺ꄗ穌넢뇌䶆멊큀퉆䐫̥괊⑆놸僥̅ᵀ㣚ꢅ뺓䇚녚伀讍홬䈕�캾撏Ჴ孢黮摠뮡䌦윃ᬳ狚䆙툾훶䏤ꛈṻ⟧㉖鮸蒵萗냤퇅서㪨瀲鰪残䓴ﯘ넃櫜㑦䢻쮓죣䕱䶘㴝姳뿝嘼ᷨ㗬꺬櫣涷꠶浒껅က㷕䩉毎覛�⧹䮯嬇힚艐Ὑ쇕횻鸙蹻硐���䈆쓖⸛錼鰙ኰ乒֐⺴썓힠䵓ꅄⵈ桃怅㾈枟⏠ﻪ폫ﺍ琖ퟰ乼�쩐鑈푷᫇﯎蕱늛�쭡�䙠ⲓᒇꪮ툅⃑ꦴ돻♹ᢋ麝熪뚭Ћ䌚�娯钮⡃㪿ᅰ⤩㥍車䎘磛蚾ㅸ擫떦蝳分鰽䠺ꭍ튘폻⥽ⳉ历⹼驿똮�⯴⋟Ḋ᛼룴꣜墭䐣앾郢�ᵸᮄ杗奪騑硼佑烑鄗䳘핬溴墽炁ࣘヲ栥풼ಃ斗狹就쵎⃺嬒瀃碂밎崹䎐貇஛汫踖�뢸숥퍞르뗿䭯䖝䱅�䵱꽔븽䢴ꁅ⟼�蒠癸ꩽ靔临䚝﹗⩏￸鍁Ꮨ䷇쁐쨒ʊ쪦鄭借滋铆ᮉ嚃ᩨ⶝ိ펇ꮼ뇄』ᰉ㕾枒鯅蛺䠿櫄築픆车똅렬㈆ﹼἋ荞괋랆偦뤰䝷핸⹝屑素蝨怀猔勛碉퀪睹�Ⓥ䍙ಗ䤮뾿谢ꁼ戻ﮖᆯ콧偪ﺯ븭碇쮢籍⁜왋壝駡暷샖଄ࣵ艫᜝䃴厫ᢉ慨䁆ꂴ೉溘欋옭螶䦗跠﨔膉痹邘⋫吪멚埣ꯕ扌옘广犵肖街�㶕畅몡ↇ꠫襤픧ၥ帻놤ਰ惘똞颤糴쫼鿋䬝穫⺁峁踷锝副鰀嗊⹀谲遲�䩢푑팾��糔뭯዇ࣷ䷴䬾갭ⶵ᾿틩魨㵻恬҅པᣄⲪ豩뛌꛵㥨몙〼△⏮큤�亃ꢡ웼ఐ칇뻻펂㢓吋䂃䨠䕱>.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:59:11+00:00Added an answer on May 11, 2026 at 6:59 pm

    (char)(r.Next(256, 65536)) can produce invalid character combinations, resulting in illegit text, so you can’t use it to create test content. This can happen even if the cast is valid and a valid character is produced. One example is surrogates in U+D800 to U+DFFF, but there are probably others.

    If you want to generate sample text from all Unicode ranges, you have to be Unicode aware when you create it, and not just cast random to char. (I think you hit upon this when you stated in the question that it worked when you supplied a more narrow range for the random number.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, which seems to override the jQuery.error function: $.test =
consider the following test class: [TestClass] public class ExampleTests { [TestMethod] public void FileDoesNotExists()
I have the following unit test defined to test my model binder: [TestMethod] public
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have an XML document which contains nodes like following:- <a class=custom>test</a> <a class=xyz></a>
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
The first part is now working [ I have the following which just seems
Is following design possible?: template <typename T> class Test{ public: template <typename Z> void
I have following code: os.chdir(os.path.dirname(os.path.realpath(__file__)) + /../test) path.append(os.getcwd()) os.chdir(os.path.dirname(os.path.realpath(__file__))) Which should add /../test to
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.