|
I think you have misunderstood something about TDD here. As Pete says, TDD doesn't specify that the project should fail, it specifies that individual tests should fail when you first write them. An empty project contains no tests, and so (obviously) nothing fails, but that's because you haven't written any tests and therefore (in pure TDD) your program has no requirements.
|
|
|
|
|
I think I understand TDD correctly. The test project is a wrapper of one or more tests. When I said that the test project fails, I meant that one or more tests (or test methods) fail.
This is the TDD workflow I use:
1) Add a test
2) Run the test
2.1) if the run succeeds, go to step 1).
2.2) if the run fails, write some source code; go to step 2).
3)Done
Note that the source code is the unit under test, not the test itself. Don't confuse TDD with normal unit test. In TDD, we create the unit test before creating the unit. The unit test should not pass before we have the unit.
Best,
Jun
|
|
|
|
|
Yes, that's correct, but until you write a test it makes no sense to worry about whether the test project compiles and runs. Actually one could argue that it should succeed because with no tests, your program has no requirements and so it will pass them all (it's easy to do nothing).
|
|
|
|
|
I am getting an odd result when trying to decompress .gz files... The method that I am using only decompresses the first 24KB of the file, but the actual content is over 100 MB.
I am using .NET 3.5, with the decompression method from the MSDN article (copied below). Has anyone seen this odd behavior before..?
private static void gDecompress(FileInfo file)
{
using (FileStream inFile = file.OpenRead())
{
string curFile = file.FullName;
string origName = curFile.Remove(curFile.Length - file.Extension.Length);
using (FileStream outFile = File.Create(origName))
{
using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
{
byte[] buffer = new byte[4096];
int numRead;
while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
{
outFile.Write(buffer, 0, numRead);
}
}
}
}
}
|
|
|
|
|
Timothy CIAN wrote: Has anyone seen this odd behavior before..?
I haven't.
I did look into MSDN a bit, and I noticed the code examples for 2.0, 3.5, and 4.0 are all different, although I can't tell why; they all look good to me.
[ADDED] I also ran the 2.0 example on a 1.5MB file, and all was well.[/ADDED]
What makes you think the decompression terminates early? Are you sure the input file is what you intend it to be, maybe you are using similar code and it has a bug somewhere. I suggest you add (re-insert) debug statements, then compare the original uncompressed file size, the compressed one, and the final decompressed one.
modified 6-Jan-12 13:13pm.
|
|
|
|
|
Well, I have it attempting to decompress a collection of .gz files which are generated as output from a 3rd-party application. However, since I don't see anyone else (via Google search) having this problem, I shall assume it is either (1) something odd about how the 3rd-party source is (mis)creating .gz files, or (2) something is wonky elsewhere with the code. #2 seems unlikely, as this is a static method that only takes a FileInfo as input. It seems fairly self-contained.
However, my next step is to create a tiny app that I can test this with (in better isolation from the "other stuff" in my code), as well as a parallel test using something like SharpZIPlib to see if there is any difference.
Thanks...
|
|
|
|
|
Update...
The .gz appears fine; I was able to extract it using WinZip (224 MB -> 877 MB). I tested Ionic's version of GZipStream, and it also resulted in a 24K file, along with the following error message:
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
Here is the Ionic-GZipStream version (which is almost identical to the previous):
private static void gDecompressIonic(FileInfo file)
{
using (FileStream inFile = file.OpenRead())
{
string curFile = file.FullName;
string origName = curFile.Remove(curFile.Length - file.Extension.Length);
using (FileStream outFile = File.Create(origName))
{
using (Ionic.Zlib.GZipStream Decompress = new Ionic.Zlib.GZipStream(inFile, Ionic.Zlib.CompressionMode.Decompress))
{
byte[] buffer = new byte[4096];
int numRead;
while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
{
outFile.Write(buffer, 0, numRead);
}
}
}
}
}
|
|
|
|
|
Timothy CIAN wrote: The .gz appears fine; I was able to extract it using WinZip
Maybe the creator is using winzip rather than a gzip library. And winzip itself is doing something odd.
Did you try a straight gzip utility?
|
|
|
|
|
Does the file use Deflate64?
WinZip handles that, but almost nothing else does.
|
|
|
|
|
FWIW: I just finished a WinZip-like (but incompatible) utility based on System.IO.Compression.GZipStream and it perfectly decompresses files it compressed before, whatever the file size is (tried up to 2MB). Typical compression ratio is about 3 except of course for PDF, JPEG, and very small files.
|
|
|
|
|
we have implemented the Compression/Decompression in C# using J# APIs. This J# supported in .Net 2.0 but MS have removed the support for J# in .Net4.0.
we are migrating to .Net 4.0 and need to rewrite J# implementation in C# as J# is no longer supported.
We tried using GZipSteam/ZipPackage but that do not provide the backward compatiblity i.e, we cannot use J# compressed file for decompressing. Also multiple file compression using GZipSteam is complex.
Is there any other solution to do compression/decompression in C# itself.(We do not want to use third party library). Is is possible to write compression/decompression algorithm in C#?
Any suggessions are welcome.
|
|
|
|
|
Yes - if you know what the algorithm J# used is. (I don't)
But an easier solution (if a bit clunky) would be to create a J# standalone module in .NET 2 and call into that from your C#.
It means you have some code base you can't alter easily, but it would ensure that you could read your existing files. You could then automatically migrate them to Zip as you come across them, so eventually the J# stuff has disappeared.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks for your infomation.
I am thinking whether we can create a module in Java that takes care of comp/decomp.
We can make use of that JAVA module in C# via interface methods. Is that would be possible?
|
|
|
|
|
Hi my freinds,
Happy new year 2012 First.
I develop some websites with .NET technologie. I want to automatise my tests. I search on the internet for test tools. i find many (NEOTYS, QF-test, NUNIT...). But i don't know what is the most performant tool. In fact, i have some rules in my deveopement (for example, in my interfaces, all textFields should be align , numbers should be rigth align...). I want to use a tool that has double function : test, network and code test.
If u have prepositions , plzzzzz tell me about I am really needing this in my work.
Regards
|
|
|
|
|
Hi,
When I try...
people.OrderBy(name => name.Name);
I get...
ex = {"An order by expression can only contain non-constant scalars that are order comparable by the server. The expression with type 'Text' is not order comparable."}
Can I get IEnumerable OrderBy to sort on a text field, using a predicate perhaps?
Thanks.
|
|
|
|
|
There must be some mistake in your code prior to your orderby call, as you should be able to order by text. As a quick demo I did this
public partial class Form1 : Form
{
List<Person> sortedPeople;
public Form1()
{
InitializeComponent();
List<Person> people = new List<Person> {new Person("wayne"), new Person("sarah"), new Person("mark"), new Person("simon"), new Person("ashleigh"), new Person("dave"), new Person("connor"), new Person("bronwyn"), new Person("chantelle"), new Person("will"), new Person("chris")};
sortedPeople = people.OrderBy(name = name.Name).ToList();
}
}
class Person
{
public Person(string name)
{
this.Name = name;
}
public string Name { get; set; }
}
and SortedPeople came out correctly
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hi,
try the below code snippet
var newList = people.OrderBy(name => name.Name).ToList();
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
Hi, thanks for looking at this.
Not sure what I am doing wrong.
I tried...
DataContext = new DataClasses1DataContext();
var people = from name in DataContext.Table_Peoples
where name.IQ < 3
select name;
var peopleOrdered = people.OrderBy(name => name.Name).ToList();
'Name' is decared as follows...
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="Text", UpdateCheck=UpdateCheck.Never)]
public string Name
{
get
{
return this._Name;
}
set
{
if ((this._Name != value))
{
this._Name = value;
}
}
}
It is still thowing the same exception.
|
|
|
|
|
Ok I got it to work like this...
DataContext = new DataClasses1DataContext();
var people = from name in DataContext.Table_Peoples
where name.IQ < 3
select name;
List<Table_People> listPeople = people.ToList();
var peopleOrdered = listPeople.OrderBy(name => name.Name).ToList();
But I dont understand why I have to copy to a List first?
|
|
|
|
|
Quote: __John_ wrote: List<Table_People> listPeople = people.ToList();
var peopleOrdered = listPeople.OrderBy(name => name.Name).ToList();
To order the list, it requires the set of names to be in a format and we are storing it as the enumerable list.
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
Hi Manognya,
I dont understand why List.OrderBy works when IEnumerable.OrderBy does not?
I am not sure what you mean when you say 'in a format'?
Thanks.
|
|
|
|
|
Hi John,
The syntax of OrderBy is:
Public Shared Function OrderBy(Of TSource, TKey) ( _
source As IEnumerable(Of TSource), _
keySelector As Func(Of TSource, TKey) _
) As IOrderedEnumerable(Of TSource)
Parameters
source
Type: System.Collections.Generic.IEnumerable(Of TSource)
A sequence of values to order.
keySelector
Type: System.Func(Of TSource, TKey)
A function to extract a key from an element.
we need to convert the source to be of type
System.Collections.Generic.IEnumerable
Hope this helps.
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
|
Thanks, it is slowly becoming clear, I probably just need to think about it a bit more.
I do sometimes find templates a bit confusing.
+5
|
|
|
|
|
Agree..templates is always little tricky(for me either )...But, Once got..makes life easy
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|