@@ -79,84 +79,3 @@ pub const AppContext = struct {
7979 // Note: We don't deinit the allocator itself here, assuming it's managed externally (e.g., GPA in main)
8080 }
8181};
82-
83- test "loadConfig" {
84- // Test the new AppContext init
85- // Use the testing allocator directly for automatic leak detection
86- const allocator = std .testing .allocator ;
87-
88- // Mock file system (Assuming a test setup or adjust paths)
89- // For simplicity, we'll assume config/config.json, config/buy-and-hold.json, data/btc.csv exist
90- // In a real scenario, you'd mock std.fs.cwd() or create temporary test files.
91-
92- // Create dummy files for testing if they don't exist
93- _ = std .fs .cwd ().makePath ("config" ) catch | err | switch (err ) {
94- error .PathAlreadyExists = > {},
95- else = > | e | return e ,
96- };
97- _ = std .fs .cwd ().makePath ("data" ) catch | err | switch (err ) {
98- error .PathAlreadyExists = > {},
99- else = > | e | return e ,
100- };
101-
102- var config_file = try std .fs .cwd ().createFile ("config/config.json" , .{});
103- defer config_file .close ();
104- _ = try config_file .writeAll (
105- \\{
106- \\ "budget": 10000,
107- \\ "strategy": "buy-and-hold.json",
108- \\ "data": "btc.csv"
109- \\}
110- );
111-
112- var strat_file = try std .fs .cwd ().createFile ("config/buy-and-hold.json" , .{});
113- defer strat_file .close ();
114- _ = try strat_file .writeAll (
115- \\{
116- \\ "buyAt": 1000
117- \\}
118- );
119-
120- var data_file = try std .fs .cwd ().createFile ("data/btc.csv" , .{});
121- defer data_file .close ();
122- _ = try data_file .writeAll (
123- \\timestamp,open,high,low,close,volume
124- \\2024-01-01T00:00:00Z,42000.00,42100.00,41900.00,42050.00,100.50
125- );
126-
127- var context = try AppContext .init (allocator );
128- defer context .deinit ();
129-
130- try std .testing .expectEqual (@as (u64 , 10000 ), context .config .value .budget );
131- try std .testing .expectEqualSlices (u8 , "buy-and-hold.json" , context .config .value .strategy );
132- try std .testing .expectEqualSlices (u8 , "btc.csv" , context .config .value .data );
133- try std .testing .expectEqual (@as (u64 , 1000 ), context .strategy .value .buyAt );
134- try std .testing .expectEqual (@as (usize , 1 ), context .ohlcvData .body .items .len ); // Check if CSV data was loaded
135-
136- // Clean up dummy files
137- try std .fs .cwd ().deleteFile ("config/config.json" );
138- try std .fs .cwd ().deleteFile ("config/buy-and-hold.json" );
139- try std .fs .cwd ().deleteFile ("data/btc.csv" );
140- try std .fs .cwd ().deleteDir ("config" );
141- try std .fs .cwd ().deleteDir ("data" );
142- }
143-
144- // Comment out old tests or remove them
145- // test "loadConfig" {
146- // const config = try loadConfig(std.testing.allocator);
147- // defer config.deinit();
148- //
149- // try std.testing.expectEqual(@as(u64, 10000), config.value.budget);
150- // try std.testing.expectEqualSlices(u8, "buy-and-hold.json", config.value.strategy);
151- // try std.testing.expectEqualSlices(u8, "btc.csv", config.value.data);
152- // }
153- //
154- // test "loadStrategySettings" {
155- // // Need to create dummy config/buy-and-hold.json for this test
156- // // ... (test setup code) ...
157- // const strat = try loadStrategySettings(std.testing.allocator, "config/buy-and-hold.json");
158- // defer strat.deinit();
159- //
160- // try std.testing.expectEqual(@as(u64, 1000), strat.value.buyAt);
161- // // ... (test cleanup code) ...
162- // }
0 commit comments