<commit_before>use ooc-base
use ooc-collections
use ooc-unit
use ooc-io

CsvWriterTest: class extends Fixture {
	init: func {
		super("CsvWriter")
		this add("open-write-verify", func {
			// Read original file
			reader := CsvReader open(Text new(c"test/io/input/3x3.csv", 21))
			csvRecords := VectorList<VectorList<Text>> new()
			for (row in reader)
				csvRecords add(row)
			reader free()
			// Write contents of original file to a temporary file
			outputFilename := Text new(c"test/io/output/3x3_temp.csv", 27)
			writer := CsvWriter open(outputFilename)
			for (i in 0 .. csvRecords count)
				writer write(csvRecords[i])
			writer free()
			// Open temporary file and verify content
			reader = CsvReader open(outputFilename)
			rowCounter := 0
			for (row in reader) {
				for (i in 0 .. row count)
					expect(row[i] toString(), is equal to(((i + 1) + rowCounter * 3) toString()))
				row free()
				++rowCounter
			}
			reader free()
			outputFilename free()
		})
	}
}
CsvWriterTest new() run()<commit_msg>creates the output directory it doesn't exist<commit_after>use ooc-base
use ooc-collections
use ooc-unit
use ooc-io
import io/File
CsvWriterTest: class extends Fixture {
	init: func {
		super("CsvWriter")
		this _createOutputDirectory()
		this add("open-write-verify", func {
			// Read original file
			reader := CsvReader open(Text new(c"test/io/input/3x3.csv", 21))
			csvRecords := VectorList<VectorList<Text>> new()
			for (row in reader)
				csvRecords add(row)
			reader free()
			// Write contents of original file to a temporary file
			outputFilename := Text new(c"test/io/output/3x3_temp.csv", 27)
			writer := CsvWriter open(outputFilename)
			for (i in 0 .. csvRecords count)
				writer write(csvRecords[i])
			writer free()
			// Open temporary file and verify content
			reader = CsvReader open(outputFilename)
			rowCounter := 0
			for (row in reader) {
				for (i in 0 .. row count)
					expect(row[i] toString(), is equal to(((i + 1) + rowCounter * 3) toString()))
				row free()
				++rowCounter
			}
			reader free()
			outputFilename free()
		})
	}
	_createOutputDirectory: func {
		file := File new("test/io/output")
		file mkdir()
		file free()
	}
}
CsvWriterTest new() run()
{'fraction_non_alphanumeric': 0.12313937753721245, 'fraction_numerical': 0.011727559765448805, 'mean_word_length': 3.4271457085828345, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5869009', 'n_tokens_mistral': 858, 'n_tokens_neox': 724, 'n_words': 224}